Coverage for python/lsst/daf/relation/_operations/_chain.py: 62%

25 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-21 09:39 +0000

1# This file is part of daf_relation. 

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 relations 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 

22from __future__ import annotations 

23 

24__all__ = ("Chain",) 

25 

26import dataclasses 

27from collections.abc import Set 

28from typing import TYPE_CHECKING, final 

29 

30from .._binary_operation import BinaryOperation 

31from .._columns import ColumnTag 

32from .._exceptions import ColumnError, EngineError 

33 

34if TYPE_CHECKING: 

35 from .._relation import Relation 

36 

37 

38@final 

39@dataclasses.dataclass(frozen=True) 

40class Chain(BinaryOperation): 

41 """A relation operation that concatenates the rows of a pair of relations 

42 with the same columns. 

43 """ 

44 

45 def __str__(self) -> str: 

46 return "∪" 

47 

48 def _begin_apply(self, lhs: Relation, rhs: Relation) -> BinaryOperation: 

49 # Docstring inherited. 

50 if lhs.engine != rhs.engine: 

51 raise EngineError(f"Mismatched chain engines: {lhs.engine} != {rhs.engine}.") 

52 if lhs.columns != rhs.columns: 

53 raise ColumnError(f"Mismatched chain columns: {set(lhs.columns)} != {set(rhs.columns)}.") 

54 return self 

55 

56 def applied_columns(self, lhs: Relation, rhs: Relation) -> Set[ColumnTag]: 

57 # Docstring inherited. 

58 return lhs.columns 

59 

60 def applied_min_rows(self, lhs: Relation, rhs: Relation) -> int: 

61 # Docstring inherited. 

62 return lhs.min_rows + rhs.min_rows 

63 

64 def applied_max_rows(self, lhs: Relation, rhs: Relation) -> int | None: 

65 # Docstring inherited. 

66 return None if lhs.max_rows is None or rhs.max_rows is None else lhs.max_rows + rhs.max_rows