Commit be47b5da authored by Wei Shoulin's avatar Wei Shoulin
Browse files

to_table

parent b72c7669
...@@ -82,14 +82,14 @@ def fields_dtypes(rec): ...@@ -82,14 +82,14 @@ def fields_dtypes(rec):
def tuple_fields_dtypes(rec: tuple): def tuple_fields_dtypes(rec: tuple):
dtypes = [] dtypes = []
for _, f in rec: for f in rec:
if f.type == int: if type(f) == int:
dtypes.append('i8') dtypes.append('i8')
elif f.type == float: elif type(f) == float:
dtypes.append('f8') dtypes.append('f8')
elif f.type == str: elif type(f) == str:
dtypes.append('S2') dtypes.append('S2')
elif f.type == list: elif type(f) == list:
dtypes.append('(12,)f8') dtypes.append('(12,)f8')
else: else:
dtypes.append('S2') dtypes.append('S2')
...@@ -101,12 +101,10 @@ def to_table(query_result): ...@@ -101,12 +101,10 @@ def to_table(query_result):
return Table() return Table()
fields = query_result['columns'] fields = query_result['columns']
dtypes = tuple_fields_dtypes(query_result.data[0]) dtypes = tuple_fields_dtypes(query_result.data[0])
t = Table(names = fields, dtype = dtypes) t = Table(names = fields, dtype = dtypes, rows = query_result.data)
t.meta['comments'] = [str(query_result.data[0].__class__)] t.meta['columns'] = fields
t.meta['total'] = query_result['totalCount'] t.meta['total'] = query_result['totalCount']
for rec in query_result.data:
t.add_row(rec)
return t return t
def object_list_to_table(query_result): def object_list_to_table(query_result):
......
...@@ -16,6 +16,7 @@ class CommonCatalogTestCase(unittest.TestCase): ...@@ -16,6 +16,7 @@ class CommonCatalogTestCase(unittest.TestCase):
ra=90, ra=90,
dec=24.5, dec=24.5,
radius=1, radius=1,
columns = ('ref_epoch','ra','ra_error','dec','dec_error','parallax','parallax_error','pmra','pmra_error','pmdec','pmdec_error','phot_g_mean_mag','source_id'),
catalog_name='gaia3', catalog_name='gaia3',
min_mag=-1, min_mag=-1,
max_mag=-1, max_mag=-1,
...@@ -23,7 +24,8 @@ class CommonCatalogTestCase(unittest.TestCase): ...@@ -23,7 +24,8 @@ class CommonCatalogTestCase(unittest.TestCase):
limit = 0 limit = 0
) )
# print(result) # print(result)
# dt = self.api.to_table(result) dt = self.api.to_table(result)
dt.pprint()
# df = dt.to_pandas() # df = dt.to_pandas()
# print(df.head()) # print(df.head())
print('used:', time.time()-t) print('used:', time.time()-t)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment