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

DM-37530: Properly retrieve astropy full table metadata with butler.get. #768

Merged
merged 2 commits into from
Jan 11, 2023
Merged
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 doc/changes/DM-37530.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Properly retrieve astropy full table metadata with butler.get.
3 changes: 3 additions & 0 deletions python/lsst/daf/butler/formatters/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ def _apply_astropy_metadata(astropy_table: atable.Table, metadata: dict) -> None
if attr in header_cols[col.name]:
setattr(col, attr, header_cols[col.name][attr])

if "meta" in meta_hdr:
astropy_table.meta.update(meta_hdr["meta"])


def _arrow_string_to_numpy_dtype(
schema: pa.Schema, name: str, numpy_column: np.ndarray | None = None, default_length: int = 10
Expand Down
20 changes: 20 additions & 0 deletions tests/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,25 @@ def testAstropyTable(self):
with self.assertRaises(ValueError):
self.butler.get(self.datasetType, dataId={}, parameters={"columns": ["e"]})

def testAstropyTableWithMetadata(self):
tab1 = _makeSimpleAstropyTable(include_multidim=True)

meta = {
"meta_a": 5,
"meta_b": 10.0,
"meta_c": [1, 2, 3],
"meta_d": True,
"meta_e": "string",
}

tab1.meta.update(meta)

self.butler.put(tab1, self.datasetType, dataId={})
# Read the whole Table.
tab2 = self.butler.get(self.datasetType, dataId={})
# This will check that the metadata is equivalent as well.
self._checkAstropyTableEquality(tab1, tab2)

def testArrowAstropySchema(self):
tab1 = _makeSimpleAstropyTable()
tab1_arrow = astropy_to_arrow(tab1)
Expand Down Expand Up @@ -801,6 +820,7 @@ def _checkAstropyTableEquality(self, table1, table2, skip_units=False):
skip_units : `bool`
"""
self.assertEqual(table1.dtype, table2.dtype)
self.assertEqual(table1.meta, table2.meta)
if not skip_units:
for name in table1.columns:
self.assertEqual(table1[name].unit, table2[name].unit)
Expand Down