Skip to content

Commit 750dcef

Browse files
committed
optimizations
1 parent 2c3b033 commit 750dcef

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/matplotlib/cbook.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,7 @@ def safe_first_element(obj):
16201620
"""
16211621
return _safe_first_finite(obj, skip_nonfinite=False)
16221622

1623+
_NoValue = object()
16231624

16241625
def _safe_first_finite(obj, *, skip_nonfinite=True):
16251626
"""
@@ -1661,7 +1662,11 @@ def safe_isfinite(val):
16611662
raise RuntimeError("matplotlib does not "
16621663
"support generators as input")
16631664
else:
1664-
return next((val for val in obj if safe_isfinite(val)), safe_first_element(obj))
1665+
value = next((val for val in obj if safe_isfinite(val)), _NoValue)
1666+
if value is _NoValue:
1667+
return safe_first_element(obj)
1668+
else:
1669+
return value
16651670

16661671

16671672
def sanitize_sequence(data):

lib/matplotlib/transforms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,14 @@ def set_children(self, *children):
189189
# Parents are stored as weak references, so that if the
190190
# parents are destroyed, references from the children won't
191191
# keep them alive.
192+
id_self = id(self)
192193
for child in children:
193194
# Use weak references so this dictionary won't keep obsolete nodes
194195
# alive; the callback deletes the dictionary entry. This is a
195196
# performance improvement over using WeakValueDictionary.
196197
ref = weakref.ref(
197-
self, lambda _, pop=child._parents.pop, k=id(self): pop(k))
198-
child._parents[id(self)] = ref
198+
self, lambda _, pop=child._parents.pop, k=id_self: pop(k))
199+
child._parents[id_self] = ref
199200

200201
def frozen(self):
201202
"""
@@ -1773,7 +1774,7 @@ def __array__(self, *args, **kwargs):
17731774

17741775
def __eq__(self, other):
17751776
if getattr(other, "is_affine", False) and hasattr(other, "get_matrix"):
1776-
return np.all(self.get_matrix() == other.get_matrix())
1777+
return (self.get_matrix() == other.get_matrix()).all()
17771778
return NotImplemented
17781779

17791780
def transform(self, values):

0 commit comments

Comments
 (0)