8000 MAINT: Remove deprecated functions · numpy/numpy@996dfbd · GitHub
[go: up one dir, main page]

Skip to content

Commit 996dfbd

Browse files
committed
MAINT: Remove deprecated functions
1 parent 3c04e81 commit 996dfbd

12 files changed

+10
-225
lines changed

numpy/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
cumprod, cumproduct, cumsum, datetime64, datetime_as_string,
141141
datetime_data, deg2rad, degrees, diagonal, divide, divmod, dot,
142142
double, dtype, e, einsum, einsum_path, empty, empty_like, equal,
143-
errstate, euler_gamma, exp, exp2, expm1, fabs, find_common_type,
143+
errstate, euler_gamma, exp, exp2, expm1, fabs,
144144
flatiter, flatnonzero, flexible,
145145
float_, float_power, floating, floor, floor_divide, fmax, fmin, fmod,
146146
format_float_positional, format_float_scientific, format_parser,
@@ -156,13 +156,13 @@
156156
logical_or, logical_xor, logspace, longcomplex, longdouble,
157157
longfloat, longlong, matmul, max, maximum, maximum_sctype,
158158
may_share_memory, mean, min, min_scalar_type, minimum, mod,
159-
modf, moveaxis, multiply, nan, nbytes, ndarray, ndim, nditer,
159+
modf, moveaxis, multiply, nan, ndarray, ndim, nditer,
160160
negative, nested_iters, newaxis, nextafter, nonzero, not_equal,
161161
number, obj2sctype, object_, ones, ones_like, outer, partition,
162162
pi, positive, power, printoptions, prod, product, promote_types,
163163
ptp, put, putmask, rad2deg, radians, ravel, rec, recarray, reciprocal,
164164
record, remainder, repeat, require, reshape, resize, result_type,
165-
right_shift, rint, roll, rollaxis, round, round_, sctype2char,
165+
right_shift, rint, roll, rollaxis, round, sctype2char,
166166
sctypeDict, sctypes, searchsorted, set_printoptions,
167167
set_string_function, setbufsize, seterr, seterrcall, shape,
168168
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
@@ -387,7 +387,6 @@ from numpy.core.numerictypes import (
387387
issubsctype as issubsctype,
388388
issubdtype as issubdtype,
389389
sctype2char as sctype2char,
390-
nbytes as nbytes,
391390
cast as cast,
392391
ScalarType as ScalarType,
393392
typecodes as typecodes,

numpy/core/_add_newdocs.py

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

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

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
]
@@ -3841,33 +3841,6 @@ def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue, *,
38413841
# avoid using them.
38423842

38433843

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

numpy/core/numerictypes.py

Lines changed: 3 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@
8989
from .._utils import set_module
9090

9191
# we add more at the bottom
92-
__all__ = ['sctypeDict', 'sctypes',
93-
'ScalarType', 'obj2sctype', 'nbytes', 'sctype2char',
94-
'maximum_sctype', 'issctype', 'typecodes', 'find_common_type',
92+
__all__ = ['sctypeDict', 'sctypes', 'ScalarType', 'obj2sctype', 'sctype2char',
93+
'maximum_sctype', 'issctype', 'typecodes',
9594
'issubdtype', 'datetime_data', 'datetime_as_string',
9695
'busday_offset', 'busday_count', 'is_busday', 'busdaycalendar',
9796
]
@@ -445,13 +444,11 @@ class _typedict(dict):
445444
def __getitem__(self, obj):
446445
return dict.__getitem__(self, obj2sctype(obj))
447446

448-
nbytes = _typedict()
449447
_maxvals = _typedict()
450448
_minvals = _typedict()
451449
def _construct_lookups():
452-
for name, info in _concrete_typeinfo.items():
450+
for info in _concrete_typeinfo.values():
453451
obj = info.type
454-
nbytes[obj] = info.bits // 8
455452
if len(info) > 5:
456453
_maxvals[obj] = info.max
457454
_minvals[obj] = info.min
@@ -546,147 +543,10 @@ def _scalar_type_key(typ):
546543
# Formal deprecation: Numpy 1.20.0, 2020-10-19 (see numpy/__init__.py)
547544
typeDict = sctypeDict
548545

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

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

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

366341
class TestMultipleFields:
367342
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
@@ -1211,7 +1211,7 @@ def __call__(self, a, b, *args, **kwargs):
12111211
negative = _MaskedUnaryOperation(umath.negative)
12121212
floor = _MaskedUnaryOperation(umath.floor)
12131213
ceil = _MaskedUnaryOperation(umath.ceil)
1214-
around = _MaskedUnaryOperation(np.round_)
1214+
around = _MaskedUnaryOperation(np.around)
12151215
logical_not = _MaskedUnaryOperation(umath.logical_not)
12161216

12171217
# Domained unary ufuncs
@@ -7868,9 +7868,9 @@ def round_(a, decimals=0, out=None):
78687868
fill_value=1e+20)
78697869
"""
78707870
if out is None:
7871-
return np.round_(a, decimals, out)
7871+
return np.round(a, decimals, out)
78727872
else:
7873-
np.round_(getdata(a), decimals, out)
7873+
np.round(getdata(a), decimals, out)
78747874
if hasattr(out, '_mask'):
78757875
out._mask = getmask(a)
78767876
return out

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
np.sctype2char("S1")
2121
np.sctype2char(list)
2222

23-
np.nbytes[int]
24-
np.nbytes["i8"]
25-
np.nbytes[np.int64]
26-
2723
np.ScalarType
2824
np.ScalarType[0]
2925
np.ScalarType[3]

numpy/typing/tests/data/reveal/numerictypes.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ reveal_type(np.cast[int]) # E: _CastFunc
2222
reveal_type(np.cast["i8"]) # E: _CastFunc
2323
reveal_type(np.cast[np.int64]) # E: _CastFunc
2424

25-
reveal_type(np.nbytes[int]) # E: int
26-
reveal_type(np.nbytes["i8"]) # E: int
27-
reveal_type(np.nbytes[np.int64]) # E: int
28-
2925
reveal_type(np.ScalarType) # E: Tuple
3026
reveal_type(np.ScalarType[0]) # E: Type[builtins.int]
3127
reveal_type(np.ScalarType[3]) # E: Type[builtins.bool]

0 commit comments

Comments
 (0)
0