10000 API: Cleaning `numpy/__init__.py` and main namespace - Part 4 [NEP 52… · Python-Repository-Hub/numpy@2f0bd6e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f0bd6e

Browse files
authored
API: Cleaning numpy/__init__.py and main namespace - Part 4 [NEP 52] (numpy#24445)
[skip ci]
1 parent aab248a commit 2f0bd6e

18 files changed

+125
-149
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* ``np.trapz`` has been deprecated. Use ``scipy.interpolate.trapezoid`` instead.
2+
3+
* ``np.in1d`` has been deprecated. Use ``np.isin`` instead.
4+
5+
* Alias ``np.row_stack`` has been deprecated. Use ``np.vstack`` directly.

doc/source/reference/routines.array-manipulation.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ Joining arrays
7272
hstack
7373
dstack
7474
column_stack
75-
row_stack
7675

7776
Splitting arrays
7877
================

doc/source/reference/routines.ma.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ Changing the number of dimensions
145145
ma.hstack
146146
ma.hsplit
147147
ma.mr_
148-
ma.row_stack
149148
ma.vstack
150149

151150

doc/source/reference/routines.math.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Sums, products, differences
6464
ediff1d
6565
gradient
6666
cross
67-
trapz
6867

6968
Exponents and logarithms
7069
------------------------

doc/source/user/quickstart.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -767,14 +767,6 @@ It is equivalent to `hstack` only for 2D arrays::
767767
array([[4., 3.],
768768
[2., 8.]])
769769

770-
On the other hand, the function `row_stack` is equivalent to `vstack`
771-
for any input arrays. In fact, `row_stack` is an alias for `vstack`::
772-
773-
>>> np.column_stack is np.hstack
774-
False
775-
>>> np.row_stack is np.vstack
776-
True
777-
778770
In general, for arrays with more than two dimensions,
779771
`hstack` stacks along their second
780772
axes, `vstack` stacks along their

numpy/core/fromnumeric.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,8 +2241,6 @@ def sum(a, axis=None, dtype=None, out=None, keepdims=np._NoValue,
22412241
22422242
cumsum : Cumulative sum of array elements.
22432243
2244-
trapz : Integration of array values using the composite trapezoidal rule.
2245-
22462244
mean, average
22472245
22482246
Notes
@@ -2544,7 +2542,6 @@ def cumsum(a, axis=None, dtype=None, out=None):
25442542
See Also
25452543
--------
25462544
sum : Sum array elements.
2547-
trapz : Integration of array values using the composite trapezoidal rule.
25482545
diff : Calculate the n-th discrete difference along given axis.
25492546
25502547
Notes

numpy/core/shape_base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ def vstack(tup, *, dtype=None, casting="same_kind"):
< 10000 /div>
230230
and r/g/b channels (third axis). The functions `concatenate`, `stack` and
231231
`block` provide more general stacking and concatenation operations.
232232
233-
``np.row_stack`` is an alias for `vstack`. They are the same function.
234-
235233
Parameters
236234
----------
237235
tup : sequence of ndarrays

numpy/core/tests/test_deprecations.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ def test_lib_functions_deprecation_call(self):
755755
from numpy.lib._shape_base_impl import get_array_wrap
756756
from numpy.core.numerictypes import maximum_sctype
757757
from numpy.lib.tests.test_io import TextIO
758+
from numpy import in1d, row_stack, trapz
758759

759760
self.assert_deprecated(lambda: safe_eval("None"))
760761

@@ -766,3 +767,7 @@ def test_lib_functions_deprecation_call(self):
766767
self.assert_deprecated(lambda: disp("test"))
767768
self.assert_deprecated(lambda: get_array_wrap())
768769
self.assert_deprecated(lambda: maximum_sctype(int))
770+
771+
self.assert_deprecated(lambda: in1d([1], [1]))
772+
self.assert_deprecated(lambda: row_stack([[]]))
773+
self.assert_deprecated(lambda: trapz([1], [1]))

numpy/core/tests/test_overrides.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -737,24 +737,3 @@ def __array__(self):
737737
bound = np.mean.__get__(MyClass) # classmethod
738738
with pytest.raises(TypeError, match="unsupported operand type"):
739739
bound()
740-
741-
742-
def test_scipy_trapz_support_shim():
743-
# SciPy 1.10 and earlier "clone" trapz in this way, so we have a
744-
# support shim in place: https://github.com/scipy/scipy/issues/17811
745-
# That should be removed eventually. This test copies what SciPy does.
746-
# Hopefully removable 1 year after SciPy 1.11; shim added to NumPy 1.25.
747-
import types
748-
import functools
749-
750-
def _copy_func(f):
751-
# Based on http://stackoverflow.com/a/6528148/190597 (Glenn Maynard)
752-
g = types.FunctionType(f.__code__, f.__globals__, name=f.__name__,
753-
argdefs=f.__defaults__, closure=f.__closure__)
754-
g = functools.update_wrapper(g, f)
755-
g.__kwdefaults__ = f.__kwdefaults__
756-
return g
757-
758-
trapezoid = _copy_func(np.trapz)
759-
760-
assert np.trapz([1, 2]) == trapezoid([1, 2])

numpy/lib/_arraysetops_impl.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
1616
"""
1717
import functools
18+
import warnings
1819

1920
import numpy as np
2021
from numpy.core import overrides
@@ -518,11 +519,12 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None):
518519
"""
519520
Test whether each element of a 1-D array is also present in a second array.
520521
522+
.. deprecated:: 2.0
523+
Use :func:`isin` instead of `in1d` for new code.
524+
521525
Returns a boolean array the same length as `ar1` that is True
522526
where an element of `ar1` is in `ar2` and False otherwise.
523527
524-
We recommend using :func:`isin` instead of `in1d` for new code.
525-
526528
Parameters
527529
----------
528530
ar1 : (M,) array_like
@@ -604,6 +606,18 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None):
604606
>>> test[mask]
605607
array([1, 5])
606608
"""
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):
607621
# Ravel both arrays, behavior for the first array could be different
608622
ar1 = np.asarray(ar1).ravel()
609623
ar2 = np.asarray(ar2).ravel()
@@ -805,10 +819,6 @@ def isin(element, test_elements, assume_unique=False, invert=False, *,
805819
Has the same shape as `element`. The values `element[isin]`
806820
are in `test_elements`.
807821
808-
See Also
809-
--------
810-
in1d : Flattened version of this function.
811-
812822
Notes
813823
-----
814824
@@ -876,8 +886,8 @@ def isin(element, test_elements, assume_unique=False, invert=False, *,
876886
[ True, False]])
877887
"""
878888
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)
881891

882892

883893
def _union1d_dispatcher(ar1, ar2):
@@ -957,4 +967,4 @@ def setdiff1d(ar1, ar2, assume_unique=False):
957967
else:
958968
ar1 = unique(ar1)
959969
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

Comments
 (0)
0