diff --git a/doc/source/user/basics.io.genfromtxt.rst b/doc/source/user/basics.io.genfromtxt.rst index a9c521fa378d..1c5d0dc8324a 100644 --- a/doc/source/user/basics.io.genfromtxt.rst +++ b/doc/source/user/basics.io.genfromtxt.rst @@ -505,20 +505,3 @@ output array will then be a :class:`~numpy.ma.MaskedArray`. .. unpack=None, loose=True, invalid_raise=True) - - -Shortcut functions -================== - -In addition to :func:`~numpy.genfromtxt`, the ``numpy.lib.npyio`` module -provides several convenience functions derived from -:func:`~numpy.genfromtxt`. These functions work the same way as the -original, but they have different default values. - -``numpy.lib.npyio.recfromtxt`` - Returns a standard :class:`numpy.recarray` (if ``usemask=False``) or a - ``numpy.ma.mrecords.MaskedRecords`` array (if ``usemaske=True``). The - default dtype is ``dtype=None``, meaning that the types of each column - will be automatically determined. -``numpy.lib.npyio.recfromcsv`` - Like ``numpy.lib.npyio.recfromtxt``, but with a default ``delimiter=","``. diff --git a/numpy/_utils/__init__.py b/numpy/_utils/__init__.py index 60703f145afe..388dd9174f35 100644 --- a/numpy/_utils/__init__.py +++ b/numpy/_utils/__init__.py @@ -8,6 +8,8 @@ in ``numpy.core``. """ +from ._convertions import asunicode, asbytes + def set_module(module): """Private decorator for overriding __module__ on a function or class. diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index a2a664f766c1..eec1535ebaaf 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -221,7 +221,7 @@ def set_printoptions(precision=None, threshold=None, edgeitems=None, See Also -------- - get_printoptions, printoptions, set_string_function, array2string + get_printoptions, printoptions, array2string Notes ----- @@ -320,7 +320,7 @@ def get_printoptions(): See Also -------- - set_printoptions, printoptions, set_string_function + set_printoptions, printoptions """ opts = _format_options.copy() @@ -1691,6 +1691,10 @@ def set_string_function(f, repr=True): """ Set a Python function to be used when pretty printing arrays. + .. deprecated:: 2.0 + Use `np.set_printoptions` instead with a formatter for custom + printing of NumPy objects. + Parameters ---------- f : function or None @@ -1738,6 +1742,16 @@ def set_string_function(f, repr=True): 'array([0, 1, 2, 3])' """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`set_string_function` is deprecated. Use `np.set_printoptions` " + "with a formatter for custom printing NumPy objects. " + "(deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + if f is None: if repr: return multiarray.set_string_function(_default_array_repr, 1) diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py index fa75d69cd2a1..4bbcf9ba93e0 100644 --- a/numpy/core/defchararray.py +++ b/numpy/core/defchararray.py @@ -24,7 +24,7 @@ from .numeric import array as narray from numpy.core.multiarray import _vec_string from numpy.core import overrides -from numpy._utils._convertions import asbytes +from numpy._utils import asbytes import numpy __all__ = [ diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index b383ad5efecf..b71547d26132 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -134,6 +134,9 @@ def maximum_sctype(t): """ Return the scalar type of highest precision of the same kind as the input. + .. deprecated:: 2.0 + Use an explicit dtype like int64 or float64 instead. + Parameters ---------- t : dtype or dtype specifier @@ -168,6 +171,15 @@ def maximum_sctype(t): # may vary """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`maximum_sctype` is deprecated. Use an explicit dtype like int64 " + "or float64 instead. (deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + g = obj2sctype(t) if g is None: return t @@ -245,7 +257,7 @@ def obj2sctype(rep, default=None): See Also -------- - sctype2char, issctype, issubsctype, issubdtype, maximum_sctype + sctype2char, issctype, issubsctype, issubdtype Examples -------- diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 3f1d3e3c1ca5..8481f10b7b18 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -777,7 +777,20 @@ def test_deprecated_np_lib_math(self): class TestLibImports(_DeprecationTestCase): # Deprecated in Numpy 1.26.0, 2023-09 def test_lib_functions_deprecation_call(self): - from numpy.lib import byte_bounds, safe_eval, who - self.assert_deprecated(lambda: byte_bounds(np.array([1]))) + from numpy import ( + byte_bounds, safe_eval, who, recfromcsv, recfromtxt, + disp, get_array_wrap, maximum_sctype + ) + from numpy.lib.tests.test_io import TextIO + self.assert_deprecated(lambda: safe_eval("None")) self.assert_deprecated(lambda: who()) + + data_gen = lambda: TextIO('A,B\n0,1\n2,3') + kwargs = dict(delimiter=",", missing_values="N/A", names=True) + self.assert_deprecated(lambda: recfromcsv(data_gen())) + self.assert_deprecated(lambda: recfromtxt(data_gen(), **kwargs)) + + self.assert_deprecated(lambda: disp("test")) + self.assert_deprecated(lambda: get_array_wrap()) + self.assert_deprecated(lambda: maximum_sctype(int)) diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index a7c89aa4380d..da6a7b891e2f 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -566,6 +566,9 @@ def assign(v): assert_raises((AttributeError, TypeError), assign, C()) assert_raises(ValueError, assign, [1]) + @pytest.mark.filterwarnings( + "ignore:.*set_string_function.*:DeprecationWarning" + ) def test_unicode_assignment(self): # gh-5049 from numpy.core.numeric import set_string_function diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 3b7019fc0441..c091fe9c3300 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -3354,6 +3354,9 @@ def test_list(self): assert_equal(np.argwhere([4, 0, 2, 1, 3]), [[0], [2], [3], [4]]) +@pytest.mark.filterwarnings( + "ignore:.*set_string_function.*:DeprecationWarning" +) class TestStringFunction: def test_set_string_function(self): diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py index bab5bf246664..dccafb71a88d 100644 --- a/numpy/core/tests/test_numerictypes.py +++ b/numpy/core/tests/test_numerictypes.py @@ -452,11 +452,13 @@ def test_ulong(self): # We will probably allow this in the future: assert not hasattr(np, 'ulong') + class TestBitName: def test_abstract(self): assert_raises(ValueError, np.core.numerictypes.bitname, np.floating) +@pytest.mark.filterwarnings("ignore:.*maximum_sctype.*:DeprecationWarning") class TestMaximumSctype: # note that parametrizing with sctype['int'] and similar would skip types diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 35763f843da7..ab8c6a24c4ff 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -16,7 +16,7 @@ _assert_valid_refcount, HAS_REFCOUNT, IS_PYSTON, IS_WASM ) from numpy.testing._private.utils import _no_tracing, requires_memory -from numpy._utils._convertions import asbytes, asunicode +from numpy._utils import asbytes, asunicode class TestRegression: diff --git a/numpy/f2py/tests/util.py b/numpy/f2py/tests/util.py index 81576c3e749d..75b257cdb825 100644 --- a/numpy/f2py/tests/util.py +++ b/numpy/f2py/tests/util.py @@ -20,7 +20,7 @@ import numpy from pathlib import Path -from numpy._utils._convertions import asunicode +from numpy._utils import asunicode from numpy.testing import temppath, IS_WASM from importlib import import_module diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index 06332d28c926..b1db4e20a249 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -5,7 +5,7 @@ import numpy as np import numpy.core.numeric as nx -from numpy._utils._convertions import asbytes, asunicode +from numpy._utils import asbytes, asunicode def _decode_line(line, encoding=None): diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index cc50fa15cde0..b4ec4ddeaf82 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1,10 +1,10 @@ +import builtins import collections.abc import functools import re import sys import warnings -from .._utils import set_module import numpy as np import numpy.core.numeric as _nx from numpy.core import transpose @@ -28,8 +28,7 @@ interp as compiled_interp, interp_complex as compiled_interp_complex ) from numpy.core.umath import _add_newdoc_ufunc as add_newdoc_ufunc - -import builtins +from numpy._utils import set_module # needed in this module for compatibility from numpy.lib.histograms import histogram, histogramdd # noqa: F401 @@ -1955,6 +1954,9 @@ def disp(mesg, device=None, linefeed=True): """ Display a message on a device. + .. deprecated:: 2.0 + Use your own printing function instead. + Parameters ---------- mesg : str @@ -1983,6 +1985,16 @@ def disp(mesg, device=None, linefeed=True): '"Display" in a file\\n' """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`disp` is deprecated, " + "use your own printing function instead. " + "(deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + if device is None: device = sys.stdout if linefeed: diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 023958259b71..a1997c3ad5f8 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -22,7 +22,7 @@ ConverterLockError, ConversionWarning, _is_string_like, has_nested_fields, flatten_dtype, easy_dtype, _decode_line ) -from numpy._utils._convertions import asunicode, asbytes +from numpy._utils import asunicode, asbytes __all__ = [ @@ -2453,6 +2453,9 @@ def recfromtxt(fname, **kwargs): If ``usemask=False`` a standard `recarray` is returned, if ``usemask=True`` a MaskedRecords array is returned. + .. deprecated:: 2.0 + Use `numpy.genfromtxt` instead. + Parameters ---------- fname, kwargs : For a description of input parameters, see `genfromtxt`. @@ -2467,6 +2470,16 @@ def recfromtxt(fname, **kwargs): array will be determined from the data. """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`recfromtxt` is deprecated, " + "use `numpy.genfromtxt` instead." + "(deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + kwargs.setdefault("dtype", None) usemask = kwargs.get('usemask', False) output = genfromtxt(fname, **kwargs) @@ -2486,6 +2499,9 @@ def recfromcsv(fname, **kwargs): `recarray`) or a masked record array (if ``usemask=True``, see `ma.mrecords.MaskedRecords`). + .. deprecated:: 2.0 + Use `numpy.genfromtxt` with comma as `delimiter` instead. + Parameters ---------- fname, kwargs : For a description of input parameters, see `genfromtxt`. @@ -2500,6 +2516,16 @@ def recfromcsv(fname, **kwargs): array will be determined from the data. """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`recfromcsv` is deprecated, " + "use `numpy.genfromtxt` with comma as `delimiter` instead. " + "(deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + # Set default kwargs for genfromtxt as relevant to csv import. kwargs.setdefault("case_sensitive", "lower") kwargs.setdefault("names", True) diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index 18f0ff5b4143..be38389a7300 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -1,4 +1,5 @@ import functools +import warnings import numpy.core.numeric as _nx from numpy.core.numeric import asarray, zeros, array, asanyarray @@ -1051,8 +1052,19 @@ def get_array_prepare(*args): def get_array_wrap(*args): """Find the wrapper for the array with the highest priority. - In case of ties, leftmost wins. If no wrapper is found, return None + In case of ties, leftmost wins. If no wrapper is found, return None. + + .. deprecated:: 2.0 """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`get_array_wrap` is deprecated. " + "(deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + wrappers = sorted((getattr(x, '__array_priority__', 0), -i, x.__array_wrap__) for i, x in enumerate(args) if hasattr(x, '__array_wrap__')) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 39f3619793cb..f7f0556a721e 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -26,7 +26,7 @@ break_cycles, IS_WASM ) from numpy.testing._private.utils import requires_memory -from numpy._utils._convertions import asbytes +from numpy._utils import asbytes class TextIO(BytesIO): @@ -1650,6 +1650,7 @@ def test_dtype_with_converters(self): control = np.array([2009., 23., 46],) assert_equal(test, control) + @pytest.mark.filterwarnings("ignore:.*recfromcsv.*:DeprecationWarning") def test_dtype_with_converters_and_usecols(self): dstr = "1,5,-1,1:1\n2,8,-1,1:n\n3,3,-2,m:n\n" dmap = {'1:1':0, '1:n':1, 'm:1':2, 'm:n':3} @@ -2290,6 +2291,7 @@ def test_utf8_file_nodtype_unicode(self): dtype=np.str_) assert_array_equal(test, ctl) + @pytest.mark.filterwarnings("ignore:.*recfromtxt.*:DeprecationWarning") def test_recfromtxt(self): # data = TextIO('A,B\n0,1\n2,3') @@ -2309,6 +2311,7 @@ def test_recfromtxt(self): assert_equal(test.mask, control.mask) assert_equal(test.A, [0, 2]) + @pytest.mark.filterwarnings("ignore:.*recfromcsv.*:DeprecationWarning") def test_recfromcsv(self): # data = TextIO('A,B\n0,1\n2,3') @@ -2609,6 +2612,7 @@ def test_genfromtxt(self, filename_type): assert_array_equal(a, data) @pytest.mark.parametrize("filename_type", [Path, str]) + @pytest.mark.filterwarnings("ignore:.*recfromtxt.*:DeprecationWarning") def test_recfromtxt(self, filename_type): with temppath(suffix='.txt') as path: path = filename_type(path) @@ -2623,6 +2627,7 @@ def test_recfromtxt(self, filename_type): assert_equal(test, control) @pytest.mark.parametrize("filename_type", [Path, str]) + @pytest.mark.filterwarnings("ignore:.*recfromcsv.*:DeprecationWarning") def test_recfromcsv(self, filename_type): with temppath(suffix='.txt') as path: path = filename_type(path) diff --git a/numpy/lib/tests/test_utils.py b/numpy/lib/tests/test_utils.py index 8594bf2e899f..f4f17b5ac701 100644 --- a/numpy/lib/tests/test_utils.py +++ b/numpy/lib/tests/test_utils.py @@ -1,119 +1,20 @@ -import inspect import sys import pytest import numpy as np from numpy.core import arange from numpy.testing import assert_, assert_equal, assert_raises_regex -from numpy.lib import deprecate, deprecate_with_doc import numpy.lib.utils as utils from io import StringIO -@deprecate -def old_func(self, x): - return x - - -@deprecate(message="Rather use new_func2") -def old_func2(self, x): - return x - - -def old_func3(self, x): - return x -new_func3 = deprecate(old_func3, old_name="old_func3", new_name="new_func3") - - -def old_func4(self, x): - """Summary. - - Further info. - """ - return x -new_func4 = deprecate(old_func4) - - -def old_func5(self, x): - """Summary. - - Bizarre indentation. - """ - return x -new_func5 = deprecate(old_func5, message="This function is\ndeprecated.") - - -def old_func6(self, x): - """ - Also in PEP-257. - """ - return x -new_func6 = deprecate(old_func6) - - -@deprecate_with_doc(msg="Rather use new_func7") -def old_func7(self,x): - return x - - -def test_deprecate_decorator(): - assert_('deprecated' in old_func.__doc__) - - -def test_deprecate_decorator_message(): - assert_('Rather use new_func2' in old_func2.__doc__) - - -def test_deprecate_fn(): - assert_('old_func3' in new_func3.__doc__) - assert_('new_func3' in new_func3.__doc__) - - -def test_deprecate_with_doc_decorator_message(): - assert_('Rather use new_func7' in old_func7.__doc__) - - -@pytest.mark.skipif(sys.flags.optimize == 2, reason="-OO discards docstrings") -@pytest.mark.parametrize('old_func, new_func', [ - (old_func4, new_func4), - (old_func5, new_func5), - (old_func6, new_func6), -]) -def test_deprecate_help_indentation(old_func, new_func): - _compare_docs(old_func, new_func) - # Ensure we don't mess up the indentation - for knd, func in (('old', old_func), ('new', new_func)): - for li, line in enumerate(func.__doc__.split('\n')): - if li == 0: - assert line.startswith(' ') or not line.startswith(' '), knd - elif line: - assert line.startswith(' '), knd - - -def _compare_docs(old_func, new_func): - old_doc = inspect.getdoc(old_func) - new_doc = inspect.getdoc(new_func) - index = new_doc.index('\n\n') + 2 - assert_equal(new_doc[index:], old_doc) - - -@pytest.mark.skipif(sys.flags.optimize == 2, reason="-OO discards docstrings") -def test_deprecate_preserve_whitespace(): - assert_('\n Bizarre' in new_func5.__doc__) - - -def test_deprecate_module(): - assert_(old_func.__module__ == __name__) - - @pytest.mark.filterwarnings("ignore:.*safe_eval.*:DeprecationWarning") def test_safe_eval_nameconstant(): # Test if safe_eval supports Python 3.4 _ast.NameConstant utils.safe_eval('None') -@pytest.mark.filterwarnings("ignore:.*byte_bounds.*:DeprecationWarning") class TestByteBounds: def test_byte_bounds(self): diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py index 3f84b80e5860..1b90b94fe696 100644 --- a/numpy/lib/type_check.py +++ b/numpy/lib/type_check.py @@ -52,7 +52,7 @@ def mintypecode(typechars, typeset='GDFgdf', default='d'): See Also -------- - dtype, sctype2char, maximum_sctype + dtype, sctype2char Examples -------- diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index adf4aac686e1..6f49b4c28526 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -7,9 +7,9 @@ import functools import platform -from .._utils import set_module from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype from numpy.core import ndarray, ufunc, asarray +from numpy._utils import set_module import numpy as np __all__ = [ @@ -191,6 +191,9 @@ def deprecate(*args, **kwargs): This function may also be used as a decorator. + .. deprecated:: 2.0 + Use `warn` with `DeprecationWarning` instead. + Parameters ---------- func : function @@ -227,6 +230,15 @@ def deprecate(*args, **kwargs): # If run as a function, we initialise the decorator class # and execute its __call__ method. + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`deprecate` is deprecated, " + "use `warn` with `DeprecationWarning` instead. " + "(deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + if args: fn = args[0] args = args[1:] @@ -240,6 +252,9 @@ def deprecate_with_doc(msg): """ Deprecates a function and includes the deprecation in its docstring. + .. deprecated:: 2.0 + Use `warn` with `DeprecationWarning` instead. + This function is used as a decorator. It returns an object that can be used to issue a DeprecationWarning, by passing the to-be decorated function as argument, this adds warning to the to-be decorated function's @@ -260,6 +275,16 @@ def deprecate_with_doc(msg): obj : object """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`deprecate` is deprecated, " + "use `warn` with `DeprecationWarning` instead. " + "(deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + return _Deprecate(message=msg) @@ -267,7 +292,7 @@ def deprecate_with_doc(msg): # Determine if two arrays can share memory #-------------------------------------------- -@deprecate + def byte_bounds(a): """ Returns pointers to the end-points of an array. @@ -325,11 +350,12 @@ def byte_bounds(a): #----------------------------------------------------------------------------- -@deprecate def who(vardict=None): """ Print the NumPy arrays in the given dictionary. + .. deprecated:: 2.0 + If there is no dictionary passed in or `vardict` is None then returns NumPy arrays in the globals() dictionary (all NumPy arrays in the namespace). @@ -370,6 +396,15 @@ def who(vardict=None): Upper bound on total bytes = 40 """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`who` is deprecated. " + "(deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + if vardict is None: frame = sys._getframe().f_back vardict = frame.f_globals @@ -690,11 +725,13 @@ def info(object=None, maxwidth=76, output=None, toplevel='numpy'): print(inspect.getdoc(object), file=output) -@deprecate def safe_eval(source): """ Protected string evaluation. + .. deprecated:: 2.0 + Use `ast.literal_eval` instead. + Evaluate a string containing a Python literal expression without allowing the execution of arbitrary non-literal code. @@ -740,6 +777,16 @@ def safe_eval(source): ValueError: malformed node or string: <_ast.Call object at 0x...> """ + + # Deprecated in NumPy 2.0, 2023-07-11 + warnings.warn( + "`safe_eval` is deprecated. Use `ast.literal_eval` instead. " + "Be aware of security implications, such as memory exhaustion " + "based attacks (deprecated in NumPy 2.0)", + DeprecationWarning, + stacklevel=2 + ) + # Local import to speed up numpy's import time. import ast return ast.literal_eval(source) diff --git a/numpy/lib/utils.pyi b/numpy/lib/utils.pyi index 52ca92774975..7a37e8ae96fa 100644 --- a/numpy/lib/utils.pyi +++ b/numpy/lib/utils.pyi @@ -8,7 +8,6 @@ from typing import ( ) from numpy import ndarray, generic - from numpy.core.numerictypes import ( issubclass_ as issubclass_, issubdtype as issubdtype, diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 65a41c75ff7c..7e5282aabaa2 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -26,7 +26,7 @@ ) from numpy.testing._private.utils import requires_memory from numpy import ndarray -from numpy._utils._convertions import asbytes +from numpy._utils import asbytes from numpy.ma.testutils import ( assert_, assert_array_equal, assert_equal, assert_almost_equal, assert_equal_records, fail_if_equal, assert_not_equal, diff --git a/numpy/typing/tests/data/fail/lib_utils.pyi b/numpy/typing/tests/data/fail/lib_utils.pyi index 4a98b2b01ed5..82463aa2b77b 100644 --- a/numpy/typing/tests/data/fail/lib_utils.pyi +++ b/numpy/typing/tests/data/fail/lib_utils.pyi @@ -1,7 +1,5 @@ import numpy as np -np.deprecate(1) # E: No overload variant - -np.deprecate_with_doc(1) # E: incompatible type +np.byte_bounds(1) # E: incompatible type np.lookfor(None) # E: incompatible type diff --git a/numpy/typing/tests/data/fail/npyio.pyi b/numpy/typing/tests/data/fail/npyio.pyi index c91b4c9cb846..396725c61f77 100644 --- a/numpy/typing/tests/data/fail/npyio.pyi +++ b/numpy/typing/tests/data/fail/npyio.pyi @@ -24,7 +24,3 @@ np.savez_compressed(str_file, AR_i8) # E: incompatible type np.loadtxt(bytes_path) # E: incompatible type np.fromregex(bytes_path, ".", np.int64) # E: No overload variant - -np.recfromtxt(bytes_path) # E: incompatible type - -np.recfromcsv(bytes_path) # E: incompatible type diff --git a/numpy/typing/tests/data/fail/numerictypes.pyi b/numpy/typing/tests/data/fail/numerictypes.pyi index ce5662d5e66a..9f4be65f81a0 100644 --- a/numpy/typing/tests/data/fail/numerictypes.pyi +++ b/numpy/typing/tests/data/fail/numerictypes.pyi @@ -1,11 +1,5 @@ import numpy as np -# Technically this works, but probably shouldn't. See -# -# https://github.com/numpy/numpy/issues/16366 -# -np.maximum_sctype(1) # E: No overload variant - np.issubsctype(1, np.int64) # E: incompatible type np.issubdtype(1, np.int64) # E: incompatible type diff --git a/numpy/typing/tests/data/pass/lib_utils.py b/numpy/typing/tests/data/pass/lib_utils.py index 78b85708cfe1..4b1dd784b082 100644 --- a/numpy/typing/tests/data/pass/lib_utils.py +++ b/numpy/typing/tests/data/pass/lib_utils.py @@ -9,11 +9,8 @@ def func(a: int) -> bool: ... -np.deprecate(func) -np.deprecate() - -np.deprecate_with_doc("test") -np.deprecate_with_doc(None) +np.byte_bounds(AR) +np.byte_bounds(np.float64()) np.info(1, output=FILE) diff --git a/numpy/typing/tests/data/pass/numerictypes.py b/numpy/typing/tests/data/pass/numerictypes.py index 8d2c5245f323..bdeeda2e027d 100644 --- a/numpy/typing/tests/data/pass/numerictypes.py +++ b/numpy/typing/tests/data/pass/numerictypes.py @@ -1,8 +1,5 @@ import numpy as np -np.maximum_sctype("S8") -np.maximum_sctype(object) - np.issctype(object) np.issctype("S8") diff --git a/numpy/typing/tests/data/reveal/lib_function_base.pyi b/numpy/typing/tests/data/reveal/lib_function_base.pyi index a8b9b01ac934..81c28711b99e 100644 --- a/numpy/typing/tests/data/reveal/lib_function_base.pyi +++ b/numpy/typing/tests/data/reveal/lib_function_base.pyi @@ -97,10 +97,6 @@ reveal_type(np.extract(AR_i8, AR_LIKE_f8)) # E: ndarray[Any, dtype[Any]] reveal_type(np.place(AR_f8, mask=AR_i8, vals=5.0)) # E: None -reveal_type(np.disp(1, linefeed=True)) # E: None -with open("test", "w") as f: - reveal_type(np.disp("message", device=f)) # E: None - reveal_type(np.cov(AR_f8, bias=True)) # E: ndarray[Any, dtype[floating[Any]]] reveal_type(np.cov(AR_f8, AR_c16, ddof=1)) # E: ndarray[Any, dtype[complexfloating[Any, Any]]] reveal_type(np.cov(AR_f8, aweights=AR_f8, dtype=np.float32)) # E: ndarray[Any, dtype[{float32}]] diff --git a/numpy/typing/tests/data/reveal/lib_utils.pyi b/numpy/typing/tests/data/reveal/lib_utils.pyi index 510160395b7e..71b8bf813b45 100644 --- a/numpy/typing/tests/data/reveal/lib_utils.pyi +++ b/numpy/typing/tests/data/reveal/lib_utils.pyi @@ -9,11 +9,8 @@ FILE: StringIO def func(a: int) -> bool: ... -reveal_type(np.deprecate(func)) # E: def (a: builtins.int) -> builtins.bool -reveal_type(np.deprecate()) # E: _Deprecate - -reveal_type(np.deprecate_with_doc("test")) # E: _Deprecate -reveal_type(np.deprecate_with_doc(None)) # E: _Deprecate +reveal_type(np.byte_bounds(AR)) # E: Tuple[builtins.int, builtins.int] +reveal_type(np.byte_bounds(np.float64())) # E: Tuple[builtins.int, builtins.int] reveal_type(np.info(1, output=FILE)) # E: None diff --git a/numpy/typing/tests/data/reveal/npyio.pyi b/numpy/typing/tests/data/reveal/npyio.pyi index 2c62d8d21edf..b5cead2f8192 100644 --- a/numpy/typing/tests/data/reveal/npyio.pyi +++ b/numpy/typing/tests/data/reveal/npyio.pyi @@ -82,11 +82,3 @@ reveal_type(np.genfromtxt(str_file, comments="test")) # E: ndarray[Any, dtype[A reveal_type(np.genfromtxt(str_path, delimiter="\n")) # E: ndarray[Any, dtype[Any]] reveal_type(np.genfromtxt(str_path, ndmin=2)) # E: ndarray[Any, dtype[Any]] reveal_type(np.genfromtxt(["1", "2", "3"], ndmin=2)) # E: ndarray[Any, dtype[Any]] - -reveal_type(np.recfromtxt(bytes_file)) # E: recarray[Any, dtype[record]] -reveal_type(np.recfromtxt(pathlib_path, usemask=True)) # E: ma.mrecords.MaskedRecords[Any, dtype[void]] -reveal_type(np.recfromtxt(["1", "2", "3"])) # E: recarray[Any, dtype[record]] - -reveal_type(np.recfromcsv(bytes_file)) # E: recarray[Any, dtype[record]] -reveal_type(np.recfromcsv(pathlib_path, usemask=True)) # E: ma.mrecords.MaskedRecords[Any, dtype[void]] -reveal_type(np.recfromcsv(["1", "2", "3"])) # E: recarray[Any, dtype[record]] diff --git a/numpy/typing/tests/data/reveal/numerictypes.pyi b/numpy/typing/tests/data/reveal/numerictypes.pyi index d4399e2b121a..613806e7efe7 100644 --- a/numpy/typing/tests/data/reveal/numerictypes.pyi +++ b/numpy/typing/tests/data/reveal/numerictypes.pyi @@ -1,8 +1,5 @@ import numpy as np -reveal_type(np.maximum_sctype(np.float64)) # E: Type[{float64}] -reveal_type(np.maximum_sctype("f8")) # E: Type[Any] - reveal_type(np.issctype(np.float64)) # E: bool reveal_type(np.issctype("foo")) # E: Literal[False] diff --git a/numpy/typing/tests/data/reveal/shape_base.pyi b/numpy/typing/tests/data/reveal/shape_base.pyi index b907a4328039..298d9e31e6bc 100644 --- a/numpy/typing/tests/data/reveal/shape_base.pyi +++ b/numpy/typing/tests/data/reveal/shape_base.pyi @@ -46,9 +46,6 @@ reveal_type(np.dsplit(AR_LIKE_f8, [3, 5, 6, 10])) # E: list[ndarray[Any, dtype[ reveal_type(np.lib.shape_base.get_array_prepare(AR_i8)) # E: lib.shape_base._ArrayPrepare reveal_type(np.lib.shape_base.get_array_prepare(AR_i8, 1)) # E: Union[None, lib.shape_base._ArrayPrepare] -reveal_type(np.get_array_wrap(AR_i8)) # E: lib.shape_base._ArrayWrap -reveal_type(np.get_array_wrap(AR_i8, 1)) # E: Union[None, lib.shape_base._ArrayWrap] - reveal_type(np.kron(AR_b, AR_b)) # E: ndarray[Any, dtype[bool_]] reveal_type(np.kron(AR_b, AR_i8)) # E: ndarray[Any, dtype[signedinteger[Any]]] reveal_type(np.kron(AR_f8, AR_f8)) # E: ndarray[Any, dtype[floating[Any]]]