Coverage for python/lsst/daf/butler/delegates/arrowastropy.py: 45%

23 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-29 02:00 -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/>. 

21 

22"""Support for reading Astropy tables with the Arrow formatter.""" 

23from __future__ import annotations 

24 

25from typing import Any 

26 

27import astropy.table as atable 

28from lsst.daf.butler.formatters.parquet import ArrowAstropySchema 

29from lsst.utils.introspection import get_full_type_name 

30 

31from .arrowtable import ArrowTableDelegate 

32 

33__all__ = ["ArrowAstropyDelegate"] 

34 

35 

36class ArrowAstropyDelegate(ArrowTableDelegate): 

37 _datasetType = atable.Table 

38 

39 def getComponent(self, composite: atable.Table, componentName: str) -> Any: 

40 """Get a component from an astropy table stored via ArrowAstropy. 

41 

42 Parameters 

43 ---------- 

44 composite : `~astropy.table.Table` 

45 Astropy table to access component. 

46 componentName : `str` 

47 Name of component to retrieve. 

48 

49 Returns 

50 ------- 

51 component : `object` 

52 The component. 

53 

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) 

66 

67 raise AttributeError( 

68 f"Do not know how to retrieve component {componentName} from {get_full_type_name(composite)}" 

69 ) 

70 

71 def _getColumns(self, inMemoryDataset: atable.Table) -> list[str]: 

72 return inMemoryDataset.columns.keys() 

73 

74 def _selectColumns(self, inMemoryDataset: atable.Table, columns: list[str]) -> atable.Table: 

75 return inMemoryDataset[columns]