Skip to content

Commit

Permalink
added eq and repr tests, and fixed shape of () not being valid
Browse files Browse the repository at this point in the history
  • Loading branch information
ESadek-MO committed Dec 24, 2024
1 parent 2a67050 commit f8c2dad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/iris/_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _assert_axioms(self):
if is_lazy and is_real:
msg = "Unexpected data state, got both lazy and real data."
raise ValueError(msg)
elif not self._shape:
elif self._shape is None:
msg = "Unexpected data state, got no lazy or real data, and no shape."
raise ValueError(msg)

Expand Down Expand Up @@ -300,7 +300,7 @@ def ndim(self):
@property
def shape(self):
"""The shape of the data being managed."""
return self._shape if self._shape else self.core_data().shape
return self._shape

def is_dataless(self) -> bool:
"""Determine whether the cube has no data.
Expand Down
17 changes: 17 additions & 0 deletions lib/iris/tests/unit/data_manager/test_DataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def test_lazy_with_lazy__dtype_failure(self):
dm2 = DataManager(as_lazy_data(self.real_array).astype(int))
self.assertFalse(dm1 == dm2)

def test_none(self):
dm1 = DataManager(data=None, shape=(1, ))
dm2 = DataManager(data=None, shape=(1, ))
self.assertTrue(dm1 == dm2)

def test_none_with_real(self):
dm1 = DataManager(data=None, shape=(1, ))
dm2 = DataManager(self.real_array)
self.assertFalse(dm1 == dm2)

def test_non_DataManager_failure(self):
dm = DataManager(np.array(0))
self.assertFalse(dm == 0)
Expand Down Expand Up @@ -158,6 +168,13 @@ def test_lazy(self):
expected = "{}({!r})".format(self.name, self.lazy_array)
self.assertEqual(result, expected)

def test_dataless(self):
print(self.real_array.shape)
dm = DataManager(None, self.real_array.shape)
result = repr(dm)
expected = "{}({!r}), shape={}".format(self.name, None, self.real_array.shape)
self.assertEqual(result, expected)


class Test__assert_axioms(tests.IrisTest):
def setUp(self):
Expand Down

0 comments on commit f8c2dad

Please sign in to comment.