Coverage for install/scipp/_extend_units.py: 20%

10 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-04-28 01:28 +0000

1from ._scipp.core import Unit as _Unit 

2from .core import scalar 

3 

4 

5def __rmul(self, value): 

6 return scalar(value, unit=self) 

7 

8 

9def __rtruediv(self, value): 

10 return scalar(value, unit=self ** (-1)) 

11 

12 

13def extend_units(): 

14 # add magic python methods to Unit class 

15 # it is done here (on python side) because 

16 # there is no proper way to do this in pybind11 

17 _Unit.__rtruediv__ = __rtruediv 

18 _Unit.__rmul__ = __rmul 

19 

20 # forbid numpy to apply ufuncs to unit 

21 # wrong behavior in scalar * unit otherwise 

22 _Unit.__array_ufunc__ = None