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

to_table

parent b72c7669
......@@ -82,14 +82,14 @@ def fields_dtypes(rec):
def tuple_fields_dtypes(rec: tuple):
dtypes = []
for _, f in rec:
if f.type == int:
for f in rec:
if type(f) == int:
dtypes.append('i8')
elif f.type == float:
elif type(f) == float:
dtypes.append('f8')
elif f.type == str:
elif type(f) == str:
dtypes.append('S2')
elif f.type == list:
elif type(f) == list:
dtypes.append('(12,)f8')
else:
dtypes.append('S2')
......@@ -101,12 +101,10 @@ def to_table(query_result):
return Table()
fields = query_result['columns']
dtypes = tuple_fields_dtypes(query_result.data[0])
t = Table(names = fields, dtype = dtypes)
t.meta['comments'] = [str(query_result.data[0].__class__)]
t = Table(names = fields, dtype = dtypes, rows = query_result.data)
t.meta['columns'] = fields
t.meta['total'] = query_result['totalCount']
for rec in query_result.data:
t.add_row(rec)
return t
def object_list_to_table(query_result):
......
......@@ -16,6 +16,7 @@ class CommonCatalogTestCase(unittest.TestCase):
ra=90,
dec=24.5,
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',
min_mag=-1,
max_mag=-1,
......@@ -23,7 +24,8 @@ class CommonCatalogTestCase(unittest.TestCase):
limit = 0
)
# print(result)
# dt = self.api.to_table(result)
dt = self.api.to_table(result)
dt.pprint()
# df = dt.to_pandas()
# print(df.head())
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