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

Skip to content

Commit 0578147

Browse files
committed
Merge pull request matplotlib#480 from efiring/numpy_copyto
cbook._putmask added to handle putmask deprecation in numpy > 1.6.x
2 parents 453381b + 49c5d5c commit 0578147

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

lib/matplotlib/cbook.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,23 @@ def is_math_text(s):
18271827

18281828
return even_dollars
18291829

1830+
# Numpy > 1.6.x deprecates putmask in favor of the new copyto.
1831+
# So long as we support versions 1.6.x and less, we need the
1832+
# following local version of putmask. We choose to make a
1833+
# local version of putmask rather than of copyto because the
1834+
# latter includes more functionality than the former. Therefore
1835+
# it is easy to make a local version that gives full putmask
1836+
# behavior, but duplicating the full copyto behavior would be
1837+
# more difficult.
1838+
1839+
try:
1840+
np.copyto
1841+
except AttributeError:
1842+
_putmask = np.putmask
1843+
else:
1844+
def _putmask(a, mask, values):
1845+
return np.copyto(a, values, where=mask)
1846+
18301847

18311848
if __name__=='__main__':
18321849
assert( allequal([1,1,1]) )

lib/matplotlib/colors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def __call__(self, X, alpha=None, bytes=False):
516516
# masked values are substituted below; no need to fill them here
517517

518518
if xa.dtype.char in np.typecodes['Float']:
519-
np.putmask(xa, xa==1.0, 0.9999999) #Treat 1.0 as slightly less than 1.
519+
cbook._putmask(xa, xa==1.0, 0.9999999) #Treat 1.0 as slightly less than 1.
520520
# The following clip is fast, and prevents possible
521521
# conversion of large positive values to negative integers.
522522

@@ -528,15 +528,15 @@ def __call__(self, X, alpha=None, bytes=False):
528528

529529
# ensure that all 'under' values will still have negative
530530
# value after casting to int
531-
np.putmask(xa, xa<0.0, -1)
531+
cbook._putmask(xa, xa<0.0, -1)
532532
xa = xa.astype(int)
533533
# Set the over-range indices before the under-range;
534534
# otherwise the under-range values get converted to over-range.
535-
np.putmask(xa, xa>self.N-1, self._i_over)
536-
np.putmask(xa, xa<0, self._i_under)
535+
cbook._putmask(xa, xa>self.N-1, self._i_over)
536+
cbook._putmask(xa, xa<0, self._i_under)
537537
if mask_bad is not None:
538538
if mask_bad.shape == xa.shape:
539-
np.putmask(xa, mask_bad, self._i_bad)
539+
cbook._putmask(xa, mask_bad, self._i_bad)
540540
elif mask_bad:
541541
xa.fill(self._i_bad)
542542
if bytes:
@@ -927,7 +927,7 @@ def __call__(self, value, clip=None):
927927
mask = (resdat <= 0)
928928
else:
929929
mask |= resdat <= 0
930-
np.putmask(resdat, mask, 1)
930+
cbook._putmask(resdat, mask, 1)
931931
np.log(resdat, resdat)
932932
resdat -= np.log(vmin)
933933
resdat /= (np.log(vmax) - np.log(vmin))

lib/matplotlib/quiver.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from matplotlib.artist import allow_rasterization
2525
from matplotlib import docstring
2626
import matplotlib.font_manager as font_manager
27+
import matplotlib.cbook as cbook
2728
from matplotlib.cbook import delete_masked_points
2829
from matplotlib.patches import CirclePolygon
2930
import math
@@ -624,8 +625,8 @@ def _h_arrows(self, length):
624625
Y0 = shrink * Y0[np.newaxis,:]
625626
short = np.repeat(length < minsh, 8, axis=1)
626627
# Now select X0, Y0 if short, otherwise X, Y
627-
np.putmask(X, short, X0)
628-
np.putmask(Y, short, Y0)
628+
cbook._putmask(X, short, X0)
629+
cbook._putmask(Y, short, Y0)
629630
if self.pivot[:3] == 'mid':
630631
X -= 0.5 * X[:,3, np.newaxis]
631632
elif self.pivot[:3] == 'tip':
@@ -641,8 +642,8 @@ def _h_arrows(self, length):
641642
X1 = np.repeat(x1[np.newaxis, :], N, axis=0)
642643
Y1 = np.repeat(y1[np.newaxis, :], N, axis=0)
643644
tooshort = np.repeat(tooshort, 8, 1)
644-
np.putmask(X, tooshort, X1)
645-
np.putmask(Y, tooshort, Y1)
645+
cbook._putmask(X, tooshort, X1)
646+
cbook._putmask(Y, tooshort, Y1)
646647
# Mask handling is deferred to the caller, _make_verts.
647648
return X, Y
648649

0 commit comments

Comments
 (0)