From f8c2daddf44424ae7683b2ca614200d40b21ddbc Mon Sep 17 00:00:00 2001 From: Elias Sadek Date: Tue, 24 Dec 2024 20:21:47 +0000 Subject: [PATCH] added eq and repr tests, and fixed shape of () not being valid --- lib/iris/_data_manager.py | 4 ++-- .../tests/unit/data_manager/test_DataManager.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/iris/_data_manager.py b/lib/iris/_data_manager.py index ecfafabe62..ea044cc180 100644 --- a/lib/iris/_data_manager.py +++ b/lib/iris/_data_manager.py @@ -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) @@ -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. diff --git a/lib/iris/tests/unit/data_manager/test_DataManager.py b/lib/iris/tests/unit/data_manager/test_DataManager.py index 342f31637b..f9ee73bc18 100644 --- a/lib/iris/tests/unit/data_manager/test_DataManager.py +++ b/lib/iris/tests/unit/data_manager/test_DataManager.py @@ -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) @@ -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):