Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified search metadata to return Astropy.Table #3950

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/3950.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modified the `search_metadata` function inside `sunpy.net.jsoc` to return the Astropy.Table instead of pandas dataframe.
11 changes: 8 additions & 3 deletions sunpy/net/jsoc/jsoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ def search_metadata(self, *query, **kwargs):
"""
query = and_(*query)
blocks = []
res = pd.DataFrame()
res = astropy.table.Table()
for block in walker.create(query):
iargs = kwargs.copy()
iargs.update(block)
iargs.update({'meta': True})
blocks.append(iargs)
res = res.append(self._lookup_records(iargs))
res = astropy.table.vstack(self._lookup_records(iargs))

return res

Expand Down Expand Up @@ -863,8 +863,13 @@ def _lookup_records(self, iargs):

# If the method was called from search_metadata(), return a Pandas Dataframe,
# otherwise return astropy.table

if isMeta:
return r
tbl = astropy.table.Table.from_pandas(r)
index = astropy.table.Column(r.index.values)
tbl.add_column(index, name='Index', index = 0)
tbl.add_index('Index')
return tbl

if r is None or r.empty:
return astropy.table.Table()
Expand Down
7 changes: 3 additions & 4 deletions sunpy/net/jsoc/tests/test_jsoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ def test_make_recordset():
def test_search_metadata():
metadata = client.search_metadata(a.Time('2014-01-01T00:00:00', '2014-01-01T00:02:00'),
a.jsoc.Series('aia.lev1_euv_12s'), a.jsoc.Wavelength(304*u.AA))
assert isinstance(metadata, pd.DataFrame)
assert metadata.shape == (11, 176)
for i in metadata.index.values:
assert (i.startswith('aia.lev1_euv_12s') and i.endswith('[304]'))
assert isinstance(metadata, astropy.table.Table)
assert (len(metadata), len(metadata.colnames)) == (11, 177)
assert metadata.primary_key[0] == 'Index'


@pytest.mark.remote_data
Expand Down