Tests each value in the array for whether it is in test elements. Parameters ---------- test_elements : array_like The values against which to test each value of `element`. This argument is flattened if an array or array_like. See numpy no
(self, test_elements: Any)
| 1359 | ) |
| 1360 | |
| 1361 | def isin(self, test_elements: Any) -> Self: |
| 1362 | """Tests each value in the array for whether it is in test elements. |
| 1363 | |
| 1364 | Parameters |
| 1365 | ---------- |
| 1366 | test_elements : array_like |
| 1367 | The values against which to test each value of `element`. |
| 1368 | This argument is flattened if an array or array_like. |
| 1369 | See numpy notes for behavior with non-array-like parameters. |
| 1370 | |
| 1371 | Returns |
| 1372 | ------- |
| 1373 | isin : DataArray or Dataset |
| 1374 | Has the same type and shape as this object, but with a bool dtype. |
| 1375 | |
| 1376 | Examples |
| 1377 | -------- |
| 1378 | >>> array = xr.DataArray([1, 2, 3], dims="x") |
| 1379 | >>> array.isin([1, 3]) |
| 1380 | <xarray.DataArray (x: 3)> Size: 3B |
| 1381 | array([ True, False, True]) |
| 1382 | Dimensions without coordinates: x |
| 1383 | |
| 1384 | See Also |
| 1385 | -------- |
| 1386 | numpy.isin |
| 1387 | """ |
| 1388 | from xarray.computation.apply_ufunc import apply_ufunc |
| 1389 | from xarray.core.dataarray import DataArray |
| 1390 | from xarray.core.dataset import Dataset |
| 1391 | from xarray.core.variable import Variable |
| 1392 | |
| 1393 | if isinstance(test_elements, Dataset): |
| 1394 | raise TypeError( |
| 1395 | f"isin() argument must be convertible to an array: {test_elements}" |
| 1396 | ) |
| 1397 | elif isinstance(test_elements, Variable | DataArray): |
| 1398 | # need to explicitly pull out data to support dask arrays as the |
| 1399 | # second argument |
| 1400 | test_elements = test_elements.data |
| 1401 | |
| 1402 | return apply_ufunc( |
| 1403 | duck_array_ops.isin, |
| 1404 | self, |
| 1405 | kwargs=dict(test_elements=test_elements), |
| 1406 | dask="allowed", |
| 1407 | ) |
| 1408 | |
| 1409 | def astype( |
| 1410 | self, |