Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45f234f

Browse files
committed
Avoided the use of the hashable property of a transform.
1 parent b96e139 commit 45f234f

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

lib/matplotlib/tests/test_transforms.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import print_function
22
import unittest
33

4-
from nose.tools import assert_equal
4+
from nose.tools import assert_equal, assert_raises
55
import numpy.testing as np_test
66
from numpy.testing import assert_almost_equal
77
from matplotlib.transforms import Affine2D, BlendedGenericTransform
@@ -242,11 +242,8 @@ def test_transform_shortcuts(self):
242242

243243
# check that we cannot find a chain from the subset back to the superset
244244
# (since the inverse of the Transform is not defined.)
245-
with self.assertRaises(ValueError):
246-
self.stack2_subset - self.stack2
247-
248-
with self.assertRaises(ValueError):
249-
self.stack1 - self.stack2
245+
assert_raises(ValueError, self.stack2_subset.__sub__, self.stack2)
246+
assert_raises(ValueError, self.stack1.__sub__, self.stack2)
250247

251248
aff1 = self.ta1 + (self.ta2 + self.ta3)
252249
aff2 = self.ta2 + self.ta3

lib/matplotlib/transforms.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,16 @@
3636
update_path_extents)
3737
from numpy.linalg import inv
3838

39-
from weakref import WeakKeyDictionary
39+
from weakref import WeakValueDictionary
4040
import warnings
4141
try:
4242
set
4343
except NameError:
4444
from sets import Set as set
4545

46-
import cbook
4746
from path import Path
4847

4948
DEBUG = False
50-
if DEBUG:
51-
import warnings
5249

5350
MaskedArray = ma.MaskedArray
5451

@@ -92,7 +89,7 @@ def __init__(self, shorthand_name=None):
9289
# Parents are stored in a WeakKeyDictionary, so that if the
9390
# parents are deleted, references from the children won't keep
9491
# them alive.
95-
self._parents = WeakKeyDictionary()
92+
self._parents = WeakValueDictionary()
9693

9794
# TransformNodes start out as invalid until their values are
9895
# computed for the first time.
@@ -141,7 +138,7 @@ def _invalidate_internal(self, value, invalidating_node):
141138
if self.pass_through or status_changed:
142139
self._invalid = value
143140

144-
for parent in self._parents.iterkeys():
141+
for parent in self._parents.itervalues():
145142
parent._invalidate_internal(value=value, invalidating_node=self)
146143

147144
def set_children(self, *children):
@@ -152,7 +149,7 @@ def set_children(self, *children):
152149
depend on other transforms.
153150
"""
154151
for child in children:
155-
child._parents[self] = None
152+
child._parents[id(self)] = self
156153

157154
if DEBUG:
158155
_set_children = set_children
@@ -1410,7 +1407,7 @@ def __init__(self, child):
14101407

14111408
def __eq__(self, other):
14121409
return self._child.__eq__(other)
1413-
1410+
14141411
if DEBUG:
14151412
def __str__(self):
14161413
return str(self._child)
@@ -1496,7 +1493,7 @@ def __eq__(self, other):
14961493
if other.is_affine:
14971494
return np.all(self.get_matrix() == other.get_matrix())
14981495
return NotImplemented
1499-
1496+
15001497
def transform(self, values):
15011498
return self.transform_affine(values)
15021499
transform.__doc__ = Transform.transform.__doc__
@@ -1642,12 +1639,12 @@ def __init__(self, matrix=None, **kwargs):
16421639
def __repr__(self):
16431640
return "Affine2D(%s)" % repr(self._mtx)
16441641

1645-
def __cmp__(self, other):
1646-
# XXX redundant. this only tells us eq.
1647-
if (isinstance(other, Affine2D) and
1648-
(self.get_matrix() == other.get_matrix()).all()):
1649-
return 0
1650-
return -1
1642+
# def __cmp__(self, other):
1643+
# # XXX redundant. this only tells us eq.
1644+
# if (isinstance(other, Affine2D) and
1645+
# (self.get_matrix() == other.get_matrix()).all()):
1646+
# return 0
1647+
# return -1
16511648

16521649
@staticmethod
16531650
def from_values(a, b, c, d, e, f):
@@ -1893,7 +1890,7 @@ def __eq__(self, other):
18931890
return self._x == other
18941891
else:
18951892
return NotImplemented
1896-
1893+
18971894
def contains_branch_seperately(self, transform):
18981895
# Note, this is an exact copy of BlendedAffine2D.contains_branch_seperately
18991896
return self._x.contains_branch(transform), self._y.contains_branch(transform)

0 commit comments

Comments
 (0)