Skip to content

Commit 5dc0d33

Browse files
committed
BF: allow CoordinateMap subclasses on L & R of ==
We were previously only testing subclasses in one direction, but a subclass on the left or the right should be OK. Test.
1 parent 62e8f17 commit 5dc0d33

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

nipy/core/reference/coordinate_map.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ def _checkfunction(self):
442442
out = self(inp)
443443

444444
def __eq__(self, other):
445-
return (isinstance(other, self.__class__)
445+
return ((isinstance(other, self.__class__) or
446+
isinstance(self, other.__class__))
446447
and (self.function == other.function)
447448
and (self.function_domain ==
448449
other.function_domain)
@@ -956,7 +957,8 @@ def __repr__(self):
956957

957958
def __eq__(self, other):
958959
# Must be subclasses
959-
if not isinstance(other, self.__class__):
960+
if not (isinstance(other, self.__class__) or
961+
isinstance(self, other.__class__)):
960962
return False
961963
if np.any(self.affine - other.affine): # for objects
962964
if not np.allclose(self.affine, other.affine): # for numerical

nipy/core/reference/tests/test_coordinate_map.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,23 @@ def test_dtype_cmap_inverses():
956956
assert_array_equal(rcm_cmap(coord), out_arr)
957957

958958

959+
def test_subtype_equalities():
960+
# Check cmap compare equal if subtypes, on either side
961+
in_cs = CoordinateSystem('ijk')
962+
out_cs = CoordinateSystem('xyz')
963+
f = lambda x : x + 1
964+
cmap = CoordinateMap(in_cs, out_cs, f)
965+
class CM2(CoordinateMap): pass
966+
cmap2 = CM2(in_cs, out_cs, f)
967+
assert_equal(cmap, cmap2)
968+
assert_equal(cmap2, cmap)
969+
cmap = AffineTransform(in_cs, out_cs, np.eye(4))
970+
class AT2(AffineTransform): pass
971+
cmap2 = AT2(in_cs, out_cs, np.eye(4))
972+
assert_equal(cmap, cmap2)
973+
assert_equal(cmap2, cmap)
974+
975+
959976
def test_cmap_coord_types():
960977
# Check that we can use full range of coordinate system types. The inverse
961978
# of an AffineTransform should generate coordinates in the input coordinate

0 commit comments

Comments
 (0)