Skip to content

Commit

Permalink
Merge pull request #4725 from neutrinoceros/numpy2.0_deprecations
Browse files Browse the repository at this point in the history
BUG: handle deprecation warnings from numpy 2.0.0dev0 (np.row_stack -> np.vstack and np.in1d -> np.isin)
  • Loading branch information
matthewturk authored Nov 2, 2023
2 parents b3cfbf9 + 03a9483 commit c2f8d50
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions yt/data_objects/particle_trajectories.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def __init__(
):
dd = ds.all_data()
newtags = dd[fds["particle_index"]].d.astype("int64")
mask = np.in1d(newtags, indices, assume_unique=True)
mask = np.isin(newtags, indices, assume_unique=True)
sort = np.argsort(newtags[mask])
array_indices = np.where(np.in1d(indices, newtags, assume_unique=True))[0]
array_indices = np.where(np.isin(indices, newtags, assume_unique=True))[0]
self.array_indices.append(array_indices)
self.masks.append(mask)
self.sorts.append(sort)
Expand Down Expand Up @@ -333,7 +333,7 @@ def trajectory_from_index(self, index):
... )
>>> plt.savefig("orbit")
"""
mask = np.in1d(self.indices, (index,), assume_unique=True)
mask = np.isin(self.indices, (index,), assume_unique=True)
if not np.any(mask):
print("The particle index %d is not in the list!" % (index))
raise IndexError
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/adaptahop/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def _set_halo_member_data(self):

# Build subregion that only contains halo particles
reg = sph.cut_region(
['np.in1d(obj[("io", "particle_identity")].astype("int64"), members)'],
['np.isin(obj[("io", "particle_identity")].astype("int64"), members)'],
locals={"members": members, "np": np},
)

Expand Down
4 changes: 2 additions & 2 deletions yt/visualization/plot_modifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2480,8 +2480,8 @@ def __call__(self, plot):
# more convenient to swap the x, y values here before final roll
x0, y0 = l_cy[0] # x, y values of start points
x1, y1 = l_cy[1] # x, y values of end points
l_cy[0] = np.row_stack([y0, x0]) # swap x, y for start points
l_cy[1] = np.row_stack([y1, x1]) # swap x, y for end points
l_cy[0] = np.vstack([y0, x0]) # swap x, y for start points
l_cy[1] = np.vstack([y1, x1]) # swap x, y for end points
# convert back to shape (nlines, 2, 2)
l_cy = np.rollaxis(l_cy, 2, 0)
# create line collection and add it to the plot
Expand Down

0 comments on commit c2f8d50

Please sign in to comment.