Skip to content

Commit 4892d78

Browse files
scottrobinson02scott.robinsonpre-commit-ci[bot]
authored
Units when dividing a coordinate by a cube (#5331)
* Commit * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: scott.robinson <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c4dcfd3 commit 4892d78

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/iris/cube.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,7 @@ def __idiv__(self, other):
37223722
def __rdiv__(self, other):
37233723
data = 1 / self.core_data()
37243724
reciprocal = self.copy(data=data)
3725+
reciprocal.units = reciprocal.units**-1
37253726
return iris.analysis.maths.multiply(reciprocal, other)
37263727

37273728
__truediv__ = __div__

lib/iris/tests/unit/cube/test_Cube.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,6 +2754,13 @@ def test_bad_coord(self):
27542754
_ = self.cube.coord(bad_coord)
27552755

27562756

2757+
class Test_coord_division_units(tests.IrisTest):
2758+
def test(self):
2759+
aux = AuxCoord(1, long_name="length", units="metres")
2760+
cube = Cube(1, units="seconds")
2761+
self.assertEqual((aux / cube).units, "m.s-1")
2762+
2763+
27572764
class Test__getitem_CellMeasure(tests.IrisTest):
27582765
def setUp(self):
27592766
cube = Cube(np.arange(6).reshape(2, 3))

0 commit comments

Comments
 (0)