Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-dfs
csst-dfs-api
Commits
48f313ef
Commit
48f313ef
authored
Jul 04, 2023
by
Wei Shoulin
Browse files
to_table_v2
parent
da5c6fee
Changes
1
Hide whitespace changes
Inline
Side-by-side
csst_dfs_api/common/utils.py
View file @
48f313ef
from
datetime
import
datetime
from
astropy.table
import
Table
import
time
import
pandas
as
pd
from
.delegate
import
Delegate
...
...
@@ -78,11 +79,11 @@ def fields_dtypes(rec):
elif
f
.
type
==
float
:
dtypes
.
append
(
'f8'
)
elif
f
.
type
==
str
:
dtypes
.
append
(
'
S2
'
)
dtypes
.
append
(
'
U11
'
)
elif
f
.
type
==
list
:
dtypes
.
append
(
'(12,)f8'
)
else
:
dtypes
.
append
(
'
S2
'
)
dtypes
.
append
(
'
U11
'
)
dtypes
=
tuple
(
dtypes
)
return
fields
,
dtypes
...
...
@@ -94,11 +95,11 @@ def tuple_fields_dtypes(rec: tuple):
elif
type
(
f
)
==
float
:
dtypes
.
append
(
'f8'
)
elif
type
(
f
)
==
str
:
dtypes
.
append
(
'
V
'
)
dtypes
.
append
(
'
U11
'
)
elif
type
(
f
)
==
list
:
dtypes
.
append
(
'(12,)f8'
)
else
:
dtypes
.
append
(
'
V
'
)
dtypes
.
append
(
'
U11
'
)
dtypes
=
tuple
(
dtypes
)
return
dtypes
...
...
@@ -110,9 +111,14 @@ def to_table(query_result):
t
=
Table
(
names
=
fields
,
dtype
=
dtypes
,
rows
=
query_result
.
data
)
t
.
meta
[
'columns'
]
=
fields
t
.
meta
[
'total'
]
=
query_result
[
'totalCount'
]
return
t
def
to_table_v2
(
query_result
):
if
not
query_result
.
success
or
not
query_result
.
data
:
return
Table
()
df
=
pd
.
DataFrame
(
data
=
query_result
.
data
,
columns
=
query_result
[
'columns'
])
return
Table
.
from_pandas
(
df
,
index
=
False
)
def
object_list_to_table
(
query_result
):
if
not
query_result
.
success
or
not
query_result
.
data
:
return
Table
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment