Skip to content

Commit

Permalink
Merge pull request #768 from lsst/tickets/DM-37530
Browse files Browse the repository at this point in the history
DM-37530: Properly retrieve astropy full table metadata with butler.get.
  • Loading branch information
erykoff committed Jan 11, 2023
2 parents ef74d6f + 21c0981 commit 927a4e4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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

0 comments on commit 927a4e4

Please sign in to comment.