Skip to content

Commit 8fda8d1

Browse files
authored
🐛 fix subset function to use np.isin for better readability and performance (#585)
* 🐛 fix subset function to use np.isin for better readability and performance * 🐛 fix order_by_date function to use np.isin for improved performance and clarity
1 parent 33609b5 commit 8fda8d1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

clouddrift/adapters/gdp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def order_by_date(df: pd.DataFrame, idx: list[int]) -> list[int]: # noqa: F821
185185
idx : list
186186
Unique set of drifter IDs sorted by their start date.
187187
"""
188-
return df.ID[np.where(np.in1d(df.ID, idx))[0]].values # type: ignore
188+
return df.ID[np.where(np.isin(df.ID, idx))[0]].values # type: ignore
189189

190190

191191
def fetch_netcdf(url: str, file: str):

clouddrift/ragged.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ def subset(
762762
mask_obs
763763
]
764764
mask_row = np.logical_and(
765-
mask_row, np.in1d(ds[id_var_name], np.unique(ids_with_mask_obs))
765+
mask_row, np.isin(ds[id_var_name], np.unique(ids_with_mask_obs))
766766
)
767767

768768
# reset mask_obs to True if we want to keep complete rows

0 commit comments

Comments
 (0)