diff --git a/clouddrift/ragged.py b/clouddrift/ragged.py index 13a77148..b3b04c48 100644 --- a/clouddrift/ragged.py +++ b/clouddrift/ragged.py @@ -791,14 +791,9 @@ def _mask_var( """ if isinstance(criterion, tuple): # min/max defining range mask = np.logical_and(var >= criterion[0], var <= criterion[1]) - elif isinstance( - criterion, (list, np.ndarray, xr.DataArray) - ): # select multiple values - # Ensure we define the mask as boolean, otherwise it will inherit - # the dtype of the variable which may be a string, object, or other. - mask = xr.zeros_like(var, dtype=bool) - for v in criterion: - mask = np.logical_or(mask, var == v) + elif isinstance(criterion, (list, np.ndarray, xr.DataArray)): + # select multiple values + mask = np.isin(var, criterion) else: # select one specific value mask = var == criterion return mask