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

1# SPDX-License-Identifier: BSD-3-Clause 

2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 

3# @author Jan-Lukas Wynen 

4 

5import dataclasses 

6 

7from ..core import Variable 

8 

9 

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 

16 

17 @property 

18 def has_dense(self) -> bool: 

19 return self.dense is not None 

20 

21 @property 

22 def has_event(self) -> bool: 

23 return self.event is not None 

24 

25 def use(self): 

26 if self.usages > 0: 

27 self.usages -= 1 

28 

29 @property 

30 def used_up(self) -> bool: 

31 return self.usages == 0 

32 

33 def has_dim(self, dim: str) -> bool: 

34 return dim in (self.dense.dims if self.has_dense else self.event.dims)