|
15 | 15 |
|
16 | 16 | """ |
17 | 17 | import functools |
| 18 | +import warnings |
18 | 19 |
|
19 | 20 | import numpy as np |
20 | 21 | from numpy.core import overrides |
@@ -518,11 +519,12 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None): |
518 | 519 | """ |
519 | 520 | Test whether each element of a 1-D array is also present in a second array. |
520 | 521 |
|
| 522 | + .. deprecated:: 2.0 |
| 523 | + Use :func:`isin` instead of `in1d` for new code. |
| 524 | +
|
521 | 525 | Returns a boolean array the same length as `ar1` that is True |
522 | 526 | where an element of `ar1` is in `ar2` and False otherwise. |
523 | 527 |
|
524 | | - We recommend using :func:`isin` instead of `in1d` for new code. |
525 | | -
|
526 | 528 | Parameters |
527 | 529 | ---------- |
528 | 530 | ar1 : (M,) array_like |
@@ -604,6 +606,18 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None): |
604 | 606 | >>> test[mask] |
605 | 607 | array([1, 5]) |
606 | 608 | """ |
| 609 | + |
| 610 | + # Deprecated in NumPy 2.0, 2023-08-18 |
| 611 | + warnings.warn( |
| 612 | + "`in1d` is deprecated. Use `np.isin` instead.", |
| 613 | + DeprecationWarning, |
| 614 | + stacklevel=2 |
| 615 | + ) |
| 616 | + |
| 617 | + return _in1d(ar1, ar2, assume_unique, invert, kind=kind) |
| 618 | + |
| 619 | + |
| 620 | +def _in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None): |
607 | 621 | # Ravel both arrays, behavior for the first array could be different |
608 | 622 | ar1 = np.asarray(ar1).ravel() |
609 | 623 | ar2 = np.asarray(ar2).ravel() |
@@ -805,10 +819,6 @@ def isin(element, test_elements, assume_unique=False, invert=False, *, |
805 | 819 | Has the same shape as `element`. The values `element[isin]` |
806 | 820 | are in `test_elements`. |
807 | 821 |
|
808 | | - See Also |
809 | | - -------- |
810 | | - in1d : Flattened version of this function. |
811 | | -
|
812 | 822 | Notes |
813 | 823 | ----- |
814 | 824 |
|
@@ -876,8 +886,8 @@ def isin(element, test_elements, assume_unique=False, invert=False, *, |
876 | 886 | [ True, False]]) |
877 | 887 | """ |
878 | 888 | element = np.asarray(element) |
879 | | - return in1d(element, test_elements, assume_unique=assume_unique, |
880 | | - invert=invert, kind=kind).reshape(element.shape) |
| 889 | + return _in1d(element, test_elements, assume_unique=assume_unique, |
| 890 | + invert=invert, kind=kind).reshape(element.shape) |
881 | 891 |
|
882 | 892 |
|
883 | 893 | def _union1d_dispatcher(ar1, ar2): |
@@ -957,4 +967,4 @@ def setdiff1d(ar1, ar2, assume_unique=False): |
957 | 967 | else: |
958 | 968 | ar1 = unique(ar1) |
959 | 969 | ar2 = unique(ar2) |
960 | | - return ar1[in1d(ar1, ar2, assume_unique=True, invert=True)] |
| 970 | + return ar1[_in1d(ar1, ar2, assume_unique=True, invert=True)] |
0 commit comments