8000 MAINT: Remove deprecated functions [NEP 52] (#24477) · numpy/numpy@b43384e · GitHub
[go: up one dir, main page]

Skip to content

Commit b43384e

Browse files
authored
MAINT: Remove deprecated functions [NEP 52] (#24477)
1 parent 39bc1b1 commit b43384e

14 files changed

+27
-228
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* ``np.find_common_type`` has been removed. Use ``numpy.promote_types`` or
2+
``numpy.result_type`` instead. To achieve semantics for the ``scalar_types``
3+
argument, use ``numpy.result_type`` and pass the Pythonvalues ``0``, ``0.0``, or ``0j``.
4+
5+
* ``np.round_`` has been removed. Use ``np.round`` instead.
6+
7+
* ``np.nbytes`` has been removed. Use ``np.dtype(<dtype>).itemsize`` instead.

numpy/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
cumprod, cumproduct, cumsum, datetime64, datetime_as_string,
137137
datetime_data, deg2rad, degrees, diagonal, divide, divmod, dot,
138138
double, dtype, e, einsum, einsum_path, empty, empty_like, equal,
139-
errstate, euler_gamma, exp, exp2, expm1, fabs, find_common_type,
139+
errstate, euler_gamma, exp, exp2, expm1, fabs,
140140
flatiter, flatnonzero, flexible,
141141
float_power, floating, floor, floor_divide, fmax, fmin, fmod,
142142
format_float_positional, format_float_scientific, format_parser,
@@ -152,13 +152,13 @@
152152
logical_or, logical_xor, logspace, longdouble,
153153
longlong, matmul, max, maximum,
154154
may_share_memory, mean, min, min_scalar_type, minimum, mod,
155-
modf, moveaxis, multiply, nan, nbytes, ndarray, ndim, nditer,
155+
modf, moveaxis, multiply, nan, ndarray, ndim, nditer,
156156
negative, nested_iters, newaxis, nextafter, nonzero, not_equal,
157157
number, object_, ones, ones_like, outer, partition,
158158
pi, positive, power, printoptions, prod, product, promote_types,
159159
ptp, put, putmask, rad2deg, radians, ravel, rec, recarray, reciprocal,
160160
record, remainder, repeat, require, reshape, resize, result_type,
161-
right_shift, rint, roll, rollaxis, round, round_,
161+
right_shift, rint, roll, rollaxis, round,
162162
searchsorted, set_printoptions,
163163
setbufsize, seterr, seterrcall, shape,
164164
shares_memory, short, sign, signbit, signedinteger, sin, single,

numpy/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ from numpy.core.numeric import (
377377

378378
from numpy.core.numerictypes import (
379379
issubdtype as issubdtype,
380-
nbytes as nbytes,
381380
cast as cast,
382381
ScalarType as ScalarType,
383382
typecodes as typecodes,

numpy/_expired_attrs_2_0.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"It's an internal function and doesn't have a replacement.",
2828
"compat": "There's no replacement, as Python 2 is no longer supported.",
2929
"safe_eval": "Use `ast.literal_eval` instead.",
30-
3130
"float_": "Use `np.float64` instead.",
3231
"complex_": "Use `np.complex128` instead.",
3332
"longfloat": "Use `np.longdouble` instead.",
@@ -41,7 +40,6 @@
4140
"Infinity": "Use `np.inf` instead.",
4241
"NaN": "Use `np.nan` instead.",
4342
"infty": "Use `np.inf` instead.",
44-
4543
"issctype": "",
4644
"maximum_sctype": "",
4745
"obj2sctype": "",
@@ -61,4 +59,11 @@
6159
"deprecate": "Raise `DeprecationWarning` instead.",
6260
"deprecate_with_doc": "Raise `DeprecationWarning` instead.",
6361
"disp": "Use your own printing function instead.",
62+
"find_common_type":
63+
"This function is deprecated, use `numpy.promote_types` or "
64+
"`numpy.result_type` instead. To achieve semantics for the "
65+
"`scalar_types` argument, use `numpy.result_type` and pass the "
66+
"Python values `0`, `0.0`, or `0j`.",
67+
"round_": "Use `np.round` instead.",
68+
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead."
6469
}

numpy/core/_add_newdocs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6644,9 +6644,6 @@ def refer_to_array_attribute(attr, method=True):
66446644
add_newdoc('numpy.core.numerictypes', 'generic', ('itemsize',
66456645
"""The length of one element in bytes."""))
66466646

6647-
add_newdoc('numpy.core.numerictypes', 'generic', ('nbytes',
6648-
"""The length of the scalar in bytes."""))
6649-
66506647
add_newdoc('numpy.core.numerictypes', 'generic', ('ndim',
66516648
"""The number of array dimensions."""))
66526649

numpy/core/fromnumeric.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'compress', 'cumprod', 'cumproduct', 'cumsum', 'diagonal', 'mean',
2424
'max', 'min',
2525
'ndim', 'nonzero', 'partition', 'prod', 'product', 'ptp', 'put',
26-
'ravel', 'repeat', 'reshape', 'resize', 'round', 'round_',
26+
'ravel', 'repeat', 'reshape', 'resize', 'round',
2727
'searchsorted', 'shape', 'size', 'sometrue', 'sort', 'squeeze',
2828
'std', 'sum', 'swapaxes', 'take', 'trace', 'transpose', 'var',
2929
]
@@ -3843,33 +3843,6 @@ def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue, *,
38433843
# avoid using them.
38443844

38453845

3846-
def _round__dispatcher(a, decimals=None, out=None):
3847-
# 2023-02-28, 1.25.0
3848-
warnings.warn("`round_` is deprecated as of NumPy 1.25.0, and will be "
3849-
"removed in NumPy 2.0. Please use `round` instead.",
3850-
DeprecationWarning, stacklevel=3)
3851-
return (a, out)
3852-
3853-
3854-
@array_function_dispatch(_round__dispatcher)
3855-
def round_(a, decimals=0, out=None):
3856-
"""
3857-
Round an array to the given number of decimals.
3858-
3859-
`~numpy.round_` is a disrecommended backwards-compatibility
3860-
alias of `~numpy.around` and `~numpy.round`.
3861-
3862-
.. deprecated:: 1.25.0
3863-
``round_`` is deprecated as of NumPy 1.25.0, and will be
3864-
removed in NumPy 2.0. Please use `round` instead.
3865-
3866-
See Also
3867-
--------
3868-
around : equivalent function; see for details.
3869-
"""
3870-
return around(a, decimals=decimals, out=out)
3871-
3872-
38733846
def _product_dispatcher(a, axis=None, dtype=None, out=None, keepdims=None,
38743847
initial=None, where=None):
38753848
# 2023-03-02, 1.25.0

numpy/core/numerictypes.py

Lines changed: 6 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@
8686
from .._utils import set_module
8787

8888
# we add more at the bottom
89-
__all__ = ['ScalarType', 'nbytes', 'typecodes', 'find_common_type',
90-
'issubdtype', 'datetime_data', 'datetime_as_string',
91-
'busday_offset', 'busday_count', 'is_busday', 'busdaycalendar',
92-
]
89+
__all__ = [
90+
'ScalarType', 'typecodes', 'issubdtype', 'datetime_data',
91+
'datetime_as_string', 'busday_offset', 'busday_count',
92+
'is_busday', 'busdaycalendar'
93+
]
9394

9495
# we don't need all these imports, but we need to keep them for compatibility
9596
# for users using np.core.numerictypes.UPPER_TABLE
@@ -443,13 +444,11 @@ class _typedict(dict):
443444
def __getitem__(self, obj):
444445
return dict.__getitem__(self, obj2sctype(obj))
445446

446-
nbytes = _typedict()
447447
_maxvals = _typedict()
448448
_minvals = _typedict()
449449
def _construct_lookups():
450-
for name, info in _concrete_typeinfo.items():
450+
for info in _concrete_typeinfo.values():
451451
obj = info.type
452-
nbytes[obj] = info.bits // 8
453452
if len(info) > 5:
454453
_maxvals[obj] = info.max
455454
_minvals[obj] = info.min
@@ -545,147 +544,10 @@ def _scalar_type_key(typ):
545544
# Formal deprecation: Numpy 1.20.0, 2020-10-19 (see numpy/__init__.py)
546545
typeDict = sctypeDict
547546

548-
# b -> boolean
549-
# u -> unsigned integer
550-
# i -> signed integer
551-
# f -> floating point
552-
# c -> complex
553-
# M -> datetime
554-
# m -> timedelta
555-
# S -> string
556-
# U -> Unicode string
557-
# V -> record
558-
# O -> Python object
559-
_kind_list = ['b', 'u', 'i', 'f', 'c', 'S', 'U', 'V', 'O', 'M', 'm']
560-
561-
__test_types = '?'+typecodes['AllInteger'][:-2]+typecodes['AllFloat']+'O'
562-
__len_test_types = len(__test_types)
563-
564-
# Keep incrementing until a common type both can be coerced to
565-
# is found. Otherwise, return None
566-
def _find_common_coerce(a, b):
567-
if a > b:
568-
return a
569-
try:
570-
thisind = __test_types.index(a.char)
571-
except ValueError:
572-
return None
573-
return _can_coerce_all([a, b], start=thisind)
574-
575-
# Find a data-type that all data-types in a list can be coerced to
576-
def _can_coerce_all(dtypelist, start=0):
577-
N = len(dtypelist)
578-
if N == 0:
579-
return None
580-
if N == 1:
581-
return dtypelist[0]
582-
thisind = start
583-
while thisind < __len_test_types:
584-
newdtype = dtype(__test_types[thisind])
585-
numcoerce = len([x for x in dtypelist if newdtype >= x])
586-
if numcoerce == N:
587-
return newdtype
588-
thisind += 1
589-
return None
590-
591547
def _register_types():
592548
numbers.Integral.register(integer)
593549
numbers.Complex.register(inexact)
594550
numbers.Real.register(floating)
595551
numbers.Number.register(number)
596552

597553
_register_types()
598-
599-
600-
@set_module('numpy')
601-
def find_common_type(array_types, scalar_types):
602-
"""
603-
Determine common type following standard coercion rules.
604-
605-
.. deprecated:: NumPy 1.25
606-
607-
This function is deprecated, use `numpy.promote_types` or
608-
`numpy.result_type` instead. To achieve semantics for the
609-
`scalar_types` argument, use `numpy.result_type` and pass the Python
610-
values `0`, `0.0`, or `0j`.
611-
This will give the same results in almost all cases.
612-
More information and rare exception can be found in the
613-
`NumPy 1.25 release notes <https://numpy.org/devdocs/release/1.25.0-notes.html>`_.
614-
615-
Parameters
616-
----------
617-
array_types : sequence
618-
A list of dtypes or dtype convertible objects representing arrays.
619-
scalar_types : sequence
620-
A list of dtypes or dtype convertible objects representing scalars.
621-
622-
Returns
623-
-------
624-
datatype : dtype
625-
The common data type, which is the maximum of `array_types` ignoring
626-
`scalar_types`, unless the maximum of `scalar_types` is of a
627-
different kind (`dtype.kind`). If the kind is not understood, then
628-
None is returned.
629-
630-
See Also
631-
--------
632-
dtype, common_type, can_cast, mintypecode
633-
634-
Examples
635-
--------
636-
>>> np.find_common_type([], [np.int64, np.float32, complex])
637-
dtype('complex128')
638-
>>> np.find_common_type([np.int64, np.float32], [])
639-
dtype('float64')
640-
641-
The standard casting rules ensure that a scalar cannot up-cast an
642-
array unless the scalar is of a fundamentally different kind of data
643-
(i.e. under a different hierarchy in the data type hierarchy) then
644-
the array:
645-
646-
>>> np.find_common_type([np.float32], [np.int64, np.float64])
647-
dtype('float32')
648-
649-
Complex is of a different type, so it up-casts the float in the
650-
`array_types` argument:
651-
652-
>>> np.find_common_type([np.float32], [complex])
653-
dtype('complex128')
654-
655-
Type specifier strings are convertible to dtypes and can therefore
656-
be used instead of dtypes:
657-
658-
>>> np.find_common_type(['f4', 'f4', 'i4'], ['c8'])
659-
dtype('complex128')
660-
661-
"""
662-
# Deprecated 2022-11-07, NumPy 1.25
663-
warnings.warn(
664-
"np.find_common_type is deprecated. Please use `np.result_type` "
665-
"or `np.promote_types`.\n"
666-
"See https://numpy.org/devdocs/release/1.25.0-notes.html and the "
667-
"docs for more information. (Deprecated NumPy 1.25)",
668-
DeprecationWarning, stacklevel=2)
669-
670-
array_types = [dtype(x) for x in array_types]
671-
scalar_types = [dtype(x) for x in scalar_types]
672-
673-
maxa = _can_coerce_all(array_types)
674-
maxsc = _can_coerce_all(scalar_types)
675-
676-
if maxa is None:
677-
return maxsc
678-
679-
if maxsc is None:
680-
return maxa
681-
682-
try:
683-
index_a = _kind_list.index(maxa.kind)
684-
index_sc = _kind_list.index(maxsc.kind)
685-
except ValueError:
686-
return None
687-
688-
if index_sc > index_a:
689-
return _find_common_coerce(maxsc, maxa)
690-
else:
691-
return maxa

numpy/core/numerictypes.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def issubdtype(arg1: DTypeLike, arg2: DTypeLike) -> bool: ...
119119
def sctype2char(sctype: DTypeLike) -> str: ...
120120

121121
cast: _typedict[_CastFunc]
122-
nbytes: _typedict[int]
123122
typecodes: _TypeCodes
124123
ScalarType: tuple[
125124
type[int],

numpy/core/tests/test_deprecations.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,6 @@ def test_deprecated_none(self):
724724
self.assert_deprecated(np.finfo, args=(None,))
725725

726726
class TestFromnumeric(_DeprecationTestCase):
727-
# 2023-02-28, 1.25.0
728-
def test_round_(self):
729-
self.assert_deprecated(lambda: np.round_(np.array([1.5, 2.5, 3.5])))
730-
731727
# 2023-03-02, 1.25.0
732728
def test_cumproduct(self):
733729
self.assert_deprecated(lambda: np.cumproduct(np.array([1, 2, 3])))

numpy/core/tests/test_numerictypes.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -338,31 +338,6 @@ def test_assign(self):
338338
assert_(a['int'].shape == (5, 0))
339339
assert_(a['float'].shape == (5, 2))
340340

341-
class TestCommonType:
342-
def test_scalar_loses1(self):
343-
with pytest.warns(DeprecationWarning, match="np.find_common_type"):
344-
res = np.find_common_type(['f4', 'f4', 'i2'], ['f8'])
345-
assert_(res == 'f4')
346-
347-
def test_scalar_loses2(self):
348-
with pytest.warns(DeprecationWarning, match="np.find_common_type"):
349-
res = np.find_common_type(['f4', 'f4'], ['i8'])
350-
assert_(res == 'f4')
351-
352-
def test_scalar_wins(self):
353-
with pytest.warns(DeprecationWarning, match="np.find_common_type"):
354-
res = np.find_common_type(['f4', 'f4', 'i2'], ['c8'])
355-
assert_(res == 'c8')
356-
357-
def test_scalar_wins2(self):
358-
with pytest.warns(DeprecationWarning, match="np.find_common_type"):
359-
res = np.find_common_type(['u4', 'i4', 'i4'], ['f4'])
360-
assert_(res == 'f8')
361-
362-
def test_scalar_wins3(self): # doesn't go up to 'f16' on purpose
363-
with pytest.warns(DeprecationWarning, match="np.find_common_type"):
364-
res = np.find_common_type(['u8', 'i8', 'i8'], ['f8'])
365-
assert_(res == 'f8')
366341

367342
class TestMultipleFields:
368343
def setup_method(self):

numpy/core/tests/test_regression.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,12 +1671,6 @@ def test_nonzero_byteswap(self):
16711671
a = a.byteswap().newbyteorder()
16721672
assert_equal(a.nonzero()[0], [1]) # [0] if nonzero() ignores swap
16731673

1674-
def test_find_common_type_boolean(self):
1675-
# Ticket #1695
1676-
with pytest.warns(DeprecationWarning, match="np.find_common_type"):
1677-
res = np.find_common_type([], ['?', '?'])
1678-
assert res == '?'
1679-
16801674
def test_empty_mul(self):
16811675
a = np.array([1.])
16821676
a[1:1] *= 2

numpy/ma/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ def __call__(self, a, b, *args, **kwargs):
12091209
negative = _MaskedUnaryOperation(umath.negative)
12101210
floor = _MaskedUnaryOperation(umath.floor)
12111211
ceil = _MaskedUnaryOperation(umath.ceil)
1212-
around = _MaskedUnaryOperation(np.round_)
1212+
around = _MaskedUnaryOperation(np.around)
12131213
logical_not = _MaskedUnaryOperation(umath.logical_not)
12141214

12151215
# Domained unary ufuncs
@@ -7871,9 +7871,9 @@ def round_(a, decimals=0, out=None):
78717871
fill_value=1e+20)
78727872
"""
78737873
if out is None:
7874-
return np.round_(a, decimals, out)
7874+
return np.round(a, decimals, out)
78757875
else:
7876-
np.round_(getdata(a), decimals, out)
7876+
np.round(getdata(a), decimals, out)
78777877
if hasattr(out, '_mask'):
78787878
out._mask = getmask(a)
78797879
return out

numpy/typing/tests/data/pass/numerictypes.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
np.issubdtype("S1", np.bytes_)
44
np.issubdtype(np.float64, np.float32)
55

6-
np.nbytes[int]
7-
np.nbytes["i8"]
8-
np.nbytes[np.int64]
9-
106
np.ScalarType
117
np.ScalarType[0]
128
np.ScalarType[3]

0 commit comments

Comments
 (0)
0