Skip to content
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

MNT: Numpy 2.0 removals from ndarray class #26762

Merged
merged 1 commit into from
Sep 14, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,8 @@ def safe_masked_invalid(x, copy=False):
if not x.dtype.isnative:
# If we have already made a copy, do the byteswap in place, else make a
# copy with the byte order swapped.
x = x.byteswap(inplace=copy).newbyteorder('N') # Swap to native order.
# Swap to native order.
x = x.byteswap(inplace=copy).view(x.dtype.newbyteorder('N'))
try:
xm = np.ma.masked_where(~(np.isfinite(x)), x, copy=False)
except TypeError:
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ def __call__(self, X, alpha=None, bytes=False):

xa = np.array(X, copy=True)
if not xa.dtype.isnative:
xa = xa.byteswap().newbyteorder() # Native byteorder is faster.
# Native byteorder is faster.
xa = xa.byteswap().view(xa.dtype.newbyteorder())
if xa.dtype.kind == "f":
xa *= self.N
# xa == 1 (== N after multiplication) is not out of range.
Expand Down Expand Up @@ -2161,7 +2162,7 @@ def rgb_to_hsv(arr):
out = np.zeros_like(arr)
arr_max = arr.max(-1)
ipos = arr_max > 0
delta = arr.ptp(-1)
delta = np.ptp(arr, -1)
s = np.zeros_like(delta)
s[ipos] = delta[ipos] / arr_max[ipos]
ipos = delta > 0
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ def test_pcolormesh():
Qz = np.sin(Y) + np.sin(X)
Qx = (Qx + 1.1)
Z = np.hypot(X, Y) / 5
Z = (Z - Z.min()) / Z.ptp()
Z = (Z - Z.min()) / np.ptp(Z)

# The color array can include masked values:
Zm = ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z)
Expand All @@ -1354,7 +1354,7 @@ def test_pcolormesh_small():
Qz = np.sin(Y) + np.sin(X)
Qx = (Qx + 1.1)
Z = np.hypot(X, Y) / 5
Z = (Z - Z.min()) / Z.ptp()
Z = (Z - Z.min()) / np.ptp(Z)
Zm = ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z)
Zm2 = ma.masked_where(Qz < -0.5 * np.max(Qz), Z)

Expand Down Expand Up @@ -1384,7 +1384,7 @@ def test_pcolormesh_alpha():
Qx = X
Qy = Y + np.sin(X)
Z = np.hypot(X, Y) / 5
Z = (Z - Z.min()) / Z.ptp()
Z = (Z - Z.min()) / np.ptp(Z)
vir = mpl.colormaps["viridis"].resampled(16)
# make another colormap with varying alpha
colors = vir(np.arange(16))
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_colormap_endian():
a = [-0.5, 0, 0.5, 1, 1.5, np.nan]
for dt in ["f2", "f4", "f8"]:
anative = np.ma.masked_invalid(np.array(a, dtype=dt))
aforeign = anative.byteswap().newbyteorder()
aforeign = anative.byteswap().view(anative.dtype.newbyteorder())
assert_array_equal(cmap(anative), cmap(aforeign))


Expand Down Expand Up @@ -1126,7 +1126,7 @@ def alternative_hillshade(azimuth, elev, z):

intensity = np.tensordot(normals, illum, axes=(2, 0))
intensity -= intensity.min()
intensity /= intensity.ptp()
intensity /= np.ptp(intensity)
return intensity

y, x = np.mgrid[5:0:-1, :5]
Expand Down