Coverage for install/scipp/coords/coord.py: 23%
22 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3# @author Jan-Lukas Wynen
5import dataclasses
7from ..core import Variable
10@dataclasses.dataclass
11class Coord:
12 dense: Variable | None # for dense variable or bin-coord
13 event: Variable | None
14 aligned: bool
15 usages: int = -1 # negative for unlimited usages
17 @property
18 def has_dense(self) -> bool:
19 return self.dense is not None
21 @property
22 def has_event(self) -> bool:
23 return self.event is not None
25 def use(self):
26 if self.usages > 0:
27 self.usages -= 1
29 @property
30 def used_up(self) -> bool:
31 return self.usages == 0
33 def has_dim(self, dim: str) -> bool:
34 return dim in (self.dense.dims if self.has_dense else self.event.dims)