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

27 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-04-13 09:32 +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: 34 ↛ 35line 34 didn't jump to line 35, because the condition on line 34 was never true

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 def __str__(self) -> str: 

45 return "∪" 

46 

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

48 # Docstring inherited. 

49 if lhs.engine != rhs.engine: 

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

51 if lhs.columns != rhs.columns: 

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

53 return self 

54 

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

56 # Docstring inherited. 

57 return lhs.columns 

58 

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

60 # Docstring inherited. 

61 return lhs.min_rows + rhs.min_rows 

62 

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

64 # Docstring inherited. 

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