Skip to content

Backport PR #26566 on branch v3.8.x (MAINT: Numpy 2.0 deprecations for row_stack and in1d) #26661

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
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
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3674,7 +3674,7 @@ def apply_mask(arrays, mask):
# elow, ehigh = np.broadcast_to(...)
# return dep - elow * ~lolims, dep + ehigh * ~uplims
# except that broadcast_to would strip units.
low, high = dep + np.row_stack([-(1 - lolims), 1 - uplims]) * err
low, high = dep + np.vstack([-(1 - lolims), 1 - uplims]) * err
barcols.append(lines_func(
*apply_mask([indep, low, high], everymask), **eb_lines_style))
if self.name == "polar" and dep_axis == "x":
Expand Down Expand Up @@ -5482,8 +5482,8 @@ def get_interp_point(idx):
collection = mcoll.PolyCollection(polys, **kwargs)

# now update the datalim and autoscale
pts = np.row_stack([np.column_stack([ind[where], dep1[where]]),
np.column_stack([ind[where], dep2[where]])])
pts = np.vstack([np.hstack([ind[where, None], dep1[where, None]]),
np.hstack([ind[where, None], dep2[where, None]])])
if ind_dir == "y":
pts = pts[:, ::-1]

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ def _update_patch_limits(self, patch):
vertices.append(curve([0, *dzeros, 1]))

if len(vertices):
vertices = np.row_stack(vertices)
vertices = np.vstack(vertices)

patch_trf = patch.get_transform()
updatex, updatey = patch_trf.contains_branch_seperately(self.transData)
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,13 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
if closed:
# This will remove contour if shorter than label
if all(i != -1 for i in I):
nlc.append(np.row_stack([xy2, lc[I[1]:I[0]+1], xy1]))
nlc.append(np.vstack([xy2, lc[I[1]:I[0]+1], xy1]))
else:
# These will remove pieces of contour if they have length zero
if I[0] != -1:
nlc.append(np.row_stack([lc[:I[0]+1], xy1]))
nlc.append(np.vstack([lc[:I[0]+1], xy1]))
if I[1] != -1:
nlc.append(np.row_stack([xy2, lc[I[1]:]]))
nlc.append(np.vstack([xy2, lc[I[1]:]]))

# The current implementation removes contours completely
# covered by labels. Uncomment line below to keep
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def transform_path_non_affine(self, path):
codes.extend(arc.codes[1:])
else: # Interpolate.
trs = cbook.simple_linear_interpolation(
np.row_stack([(last_t, last_r), trs]),
np.vstack([(last_t, last_r), trs]),
path._interpolation_steps)[1:]
xys.extend(self.transform_non_affine(trs))
codes.extend([Path.LINETO] * len(trs))
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/stackplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def stackplot(axes, x, *args,
stacked area plot.
"""

y = np.row_stack(args)
y = np.vstack(args)

labels = iter(labels)
if colors is not None:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ def test_trirefine():
x_verif, y_verif = np.meshgrid(x_verif, x_verif)
x_verif = x_verif.ravel()
y_verif = y_verif.ravel()
ind1d = np.in1d(np.around(x_verif*(2.5+y_verif), 8),
ind1d = np.isin(np.around(x_verif*(2.5+y_verif), 8),
np.around(x_refi*(2.5+y_refi), 8))
assert_array_equal(ind1d, True)

Expand Down
4 changes: 2 additions & 2 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,8 @@ def set_zsort(self, zsort):
def get_vector(self, segments3d):
"""Optimize points for projection."""
if len(segments3d):
xs, ys, zs = np.row_stack(segments3d).T
else: # row_stack can't stack zero arrays.
xs, ys, zs = np.vstack(segments3d).T
else: # vstack can't stack zero arrays.
xs, ys, zs = [], [], []
ones = np.ones(len(xs))
self._vec = np.array([xs, ys, zs, ones])
Expand Down