diff --git a/cf_units/__init__.py b/cf_units/__init__.py index 847a636e..3f24f931 100644 --- a/cf_units/__init__.py +++ b/cf_units/__init__.py @@ -1731,7 +1731,10 @@ def __eq__(self, other): True """ - other = as_unit(other) + try: + other = as_unit(other) + except ValueError: + return NotImplemented # Compare category (i.e. unknown, no_unit, etc.). if self.category != other.category: diff --git a/cf_units/tests/test_unit.py b/cf_units/tests/test_unit.py index a96f14c3..ed5102e7 100644 --- a/cf_units/tests/test_unit.py +++ b/cf_units/tests/test_unit.py @@ -667,6 +667,10 @@ def test_unknown_no_unit(self): v = Unit('no_unit') self.assertNotEqual(u, v) + def test_not_implemented(self): + u = Unit('meter') + self.assertFalse(u == {}) + class Test_non_equality(unittest.TestCase): @@ -695,6 +699,10 @@ def test_no_unit(self): u = Unit('no_unit') self.assertFalse(u != 'no_unit') + def test_not_implemented(self): + u = Unit('meter') + self.assertNotEqual(u, {}) + class Test_convert(unittest.TestCase):