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

Skip to content
Merged
Prev Previous commit
Next Next commit
Avoided the use of the hashable property of a transform.
  • Loading branch information
pelson committed Aug 20, 2012
commit 45f234f7da0948bd319af4f7be633ca82d5744d9
9 changes: 3 additions & 6 deletions lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function
import unittest

from nose.tools import assert_equal
from nose.tools import assert_equal, assert_raises
import numpy.testing as np_test
from numpy.testing import assert_almost_equal
from matplotlib.transforms import Affine2D, BlendedGenericTransform
Expand Down Expand Up @@ -242,11 +242,8 @@ def test_transform_shortcuts(self):

# check that we cannot find a chain from the subset back to the superset
# (since the inverse of the Transform is not defined.)
with self.assertRaises(ValueError):
self.stack2_subset - self.stack2

with self.assertRaises(ValueError):
self.stack1 - self.stack2
assert_raises(ValueError, self.stack2_subset.__sub__, self.stack2)
assert_raises(ValueError, self.stack1.__sub__, self.stack2)

aff1 = self.ta1 + (self.ta2 + self.ta3)
aff2 = self.ta2 + self.ta3
Expand Down
29 changes: 13 additions & 16 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@
update_path_extents)
from numpy.linalg import inv

from weakref import WeakKeyDictionary
from weakref import WeakValueDictionary
import warnings
try:
set
except NameError:
from sets import Set as set

import cbook
from path import Path

DEBUG = False
if DEBUG:
import warnings

MaskedArray = ma.MaskedArray

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

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

for parent in self._parents.iterkeys():
for parent in self._parents.itervalues():
parent._invalidate_internal(value=value, invalidating_node=self)

def set_children(self, *children):
Expand All @@ -152,7 +149,7 @@ def set_children(self, *children):
depend on other transforms.
"""
for child in children:
child._parents[self] = None
child._parents[id(self)] = self

if DEBUG:
_set_children = set_children
Expand Down Expand Up @@ -1410,7 +1407,7 @@ def __init__(self, child):

def __eq__(self, other):
return self._child.__eq__(other)

if DEBUG:
def __str__(self):
return str(self._child)
Expand Down Expand Up @@ -1496,7 +1493,7 @@ def __eq__(self, other):
if other.is_affine:
return np.all(self.get_matrix() == other.get_matrix())
return NotImplemented

def transform(self, values):
return self.transform_affine(values)
transform.__doc__ = Transform.transform.__doc__
Expand Down Expand Up @@ -1642,12 +1639,12 @@ def __init__(self, matrix=None, **kwargs):
def __repr__(self):
return "Affine2D(%s)" % repr(self._mtx)

def __cmp__(self, other):
# XXX redundant. this only tells us eq.
if (isinstance(other, Affine2D) and
(self.get_matrix() == other.get_matrix()).all()):
return 0
return -1
# def __cmp__(self, other):
# # XXX redundant. this only tells us eq.
# if (isinstance(other, Affine2D) and
# (self.get_matrix() == other.get_matrix()).all()):
# return 0
# return -1

@staticmethod
def from_values(a, b, c, d, e, f):
Expand Down Expand Up @@ -1893,7 +1890,7 @@ def __eq__(self, other):
return self._x == other
else:
return NotImplemented

def contains_branch_seperately(self, transform):
# Note, this is an exact copy of BlendedAffine2D.contains_branch_seperately
return self._x.contains_branch(transform), self._y.contains_branch(transform)
Expand Down