diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/function_base.py | 26 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 7 |
2 files changed, 3 insertions, 30 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 41caa805e..6ea9cc4de 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -4733,12 +4733,12 @@ def append(arr, values, axis=None): return concatenate((arr, values), axis=axis) -def _digitize_dispatcher(x, bins, right=None, edge=None): +def _digitize_dispatcher(x, bins, right=None): return (x, bins) @array_function_dispatch(_digitize_dispatcher) -def digitize(x, bins, right=False, edge=False): +def digitize(x, bins, right=False): """ Return the indices of the bins to which each value in input array belongs. @@ -4767,10 +4767,6 @@ def digitize(x, bins, right=False, edge=False): does not include the right edge. The left bin end is open in this case, i.e., bins[i-1] <= x < bins[i] is the default behavior for monotonically increasing bins. - edge : bool, optional - Whether to include the last right edge if right==False or the first - left edge if right==True so that the whole interval from the least - to the greatest value of bins is covered. Returns ------- @@ -4786,7 +4782,7 @@ def digitize(x, bins, right=False, edge=False): See Also -------- - bincount, histogram, unique, nextafter, searchsorted + bincount, histogram, unique, searchsorted Notes ----- @@ -4843,22 +4839,6 @@ def digitize(x, bins, right=False, edge=False): if mono == 0: raise ValueError("bins must be monotonically increasing or decreasing") - if edge: - # ========= ============= ============================ ===== ===== - # `right` order of bins returned index `i` satisfies delta index - # ========= ============= ============================ ===== ===== - # ``False`` increasing ``bins[i-1] <= x < bins[i]`` 1 -1 - # ``True`` increasing ``bins[i-1] < x <= bins[i]`` -1 0 - # ``False`` decreasing ``bins[i-1] > x >= bins[i]`` 1 0 - # ``True`` decreasing ``bins[i-1] >= x > bins[i]`` -1 -1 - # ========= ============= ============================ ===== ===== - delta = -1 if right else 1 - idx = -1 if delta == mono else 0 - if np.issubdtype(bins.dtype, _nx.integer): - bins[idx] += delta - else: - bins[idx] = np.nextafter(bins[idx], bins[idx] + delta) - # this is backwards because the arguments below are swapped side = 'left' if right else 'right' if mono == -1: diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 32f660772..eb2fc3311 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1712,12 +1712,6 @@ class TestDigitize: bins = [1, 1, 0] assert_array_equal(digitize(x, bins, False), [3, 2, 0, 0]) assert_array_equal(digitize(x, bins, True), [3, 3, 2, 0]) - bins = [-1, 0, 1, 2] - assert_array_equal(digitize(x, bins, False, True), [1, 2, 3, 3]) - assert_array_equal(digitize(x, bins, True, True), [1, 1, 2, 3]) - bins = [2, 1, 0, -1] - assert_array_equal(digitize(x, bins, False, True), [3, 2, 1, 1]) - assert_array_equal(digitize(x, bins, True, True), [3, 3, 2, 1]) bins = [1, 1, 1, 1] assert_array_equal(digitize(x, bins, False), [0, 0, 4, 4]) assert_array_equal(digitize(x, bins, True), [0, 0, 0, 4]) @@ -1746,7 +1740,6 @@ class TestDigitize: # gh-11022 x = 2**54 # loses precision in a float assert_equal(np.digitize(x, [x - 1, x + 1]), 1) - assert_equal(np.digitize(x, [x - 1, x + 1], False, True), 1) @pytest.mark.xfail( reason="gh-11022: np.core.multiarray._monoticity loses precision") |