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

Skip to content

cbook._putmask added to handle putmask deprecation in numpy > 1.6.x #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,23 @@ def is_math_text(s):

return even_dollars

# Numpy > 1.6.x deprecates putmask in favor of the new copyto.
# So long as we support versions 1.6.x and less, we need the
# following local version of putmask. We choose to make a
# local version of putmask rather than of copyto because the
# latter includes more functionality than the former. Therefore
# it is easy to make a local version that gives full putmask
# behavior, but duplicating the full copyto behavior would be
# more difficult.

try:
np.copyto
except AttributeError:
_putmask = np.putmask
else:
def _putmask(a, mask, values):
return np.copyto(a, values, where=mask)


if __name__=='__main__':
assert( allequal([1,1,1]) )
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def __call__(self, X, alpha=None, bytes=False):
# masked values are substituted below; no need to fill them here

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

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

# ensure that all 'under' values will still have negative
# value after casting to int
np.putmask(xa, xa<0.0, -1)
cbook._putmask(xa, xa<0.0, -1)
xa = xa.astype(int)
# Set the over-range indices before the under-range;
# otherwise the under-range values get converted to over-range.
np.putmask(xa, xa>self.N-1, self._i_over)
np.putmask(xa, xa<0, self._i_under)
cbook._putmask(xa, xa>self.N-1, self._i_over)
cbook._putmask(xa, xa<0, self._i_under)
if mask_bad is not None:
if mask_bad.shape == xa.shape:
np.putmask(xa, mask_bad, self._i_bad)
cbook._putmask(xa, mask_bad, self._i_bad)
elif mask_bad:
xa.fill(self._i_bad)
if bytes:
Expand Down Expand Up @@ -927,7 +927,7 @@ def __call__(self, value, clip=None):
mask = (resdat <= 0)
else:
mask |= resdat <= 0
np.putmask(resdat, mask, 1)
cbook._putmask(resdat, mask, 1)
np.log(resdat, resdat)
resdat -= np.log(vmin)
resdat /= (np.log(vmax) - np.log(vmin))
Expand Down
9 changes: 5 additions & 4 deletions lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from matplotlib.artist import allow_rasterization
from matplotlib import docstring
import matplotlib.font_manager as font_manager
import matplotlib.cbook as cbook
from matplotlib.cbook import delete_masked_points
from matplotlib.patches import CirclePolygon
import math
Expand Down Expand Up @@ -624,8 +625,8 @@ def _h_arrows(self, length):
Y0 = shrink * Y0[np.newaxis,:]
short = np.repeat(length < minsh, 8, axis=1)
# Now select X0, Y0 if short, otherwise X, Y
np.putmask(X, short, X0)
np.putmask(Y, short, Y0)
cbook._putmask(X, short, X0)
cbook._putmask(Y, short, Y0)
if self.pivot[:3] == 'mid':
X -= 0.5 * X[:,3, np.newaxis]
elif self.pivot[:3] == 'tip':
Expand All @@ -641,8 +642,8 @@ def _h_arrows(self, length):
X1 = np.repeat(x1[np.newaxis, :], N, axis=0)
Y1 = np.repeat(y1[np.newaxis, :], N, axis=0)
tooshort = np.repeat(tooshort, 8, 1)
np.putmask(X, tooshort, X1)
np.putmask(Y, tooshort, Y1)
cbook._putmask(X, tooshort, X1)
cbook._putmask(Y, tooshort, Y1)
# Mask handling is deferred to the caller, _make_verts.
return X, Y

Expand Down