Coverage for python/lsst/daf/butler/delegates/arrowastropy.py: 45%
23 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-11 02:31 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-11 02:31 -0800
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Support for reading Astropy tables with the Arrow formatter."""
23from __future__ import annotations
25from typing import Any
27import astropy.table as atable
28from lsst.daf.butler.formatters.parquet import ArrowAstropySchema
29from lsst.utils.introspection import get_full_type_name
31from .arrowtable import ArrowTableDelegate
33__all__ = ["ArrowAstropyDelegate"]
36class ArrowAstropyDelegate(ArrowTableDelegate):
37 _datasetType = atable.Table
39 def getComponent(self, composite: atable.Table, componentName: str) -> Any:
40 """Get a component from an astropy table stored via ArrowAstropy.
42 Parameters
43 ----------
44 composite : `~astropy.table.Table`
45 Astropy table to access component.
46 componentName : `str`
47 Name of component to retrieve.
49 Returns
50 -------
51 component : `object`
52 The component.
54 Raises
55 ------
56 AttributeError
57 The component can not be found.
58 """
59 match componentName:
60 case "columns":
61 return list(composite.columns.keys())
62 case "schema":
63 return ArrowAstropySchema(composite)
64 case "rowcount":
65 return len(composite)
67 raise AttributeError(
68 f"Do not know how to retrieve component {componentName} from {get_full_type_name(composite)}"
69 )
71 def _getColumns(self, inMemoryDataset: atable.Table) -> list[str]:
72 return inMemoryDataset.columns.keys()
74 def _selectColumns(self, inMemoryDataset: atable.Table, columns: list[str]) -> atable.Table:
75 return inMemoryDataset[columns]