Skip to content

Commit 0ea5e62

Browse files
committed
MAINT: Remove np.int_ and np.uint
1 parent 7e68183 commit 0ea5e62

31 files changed

+73
-49
lines changed

doc/source/user_guide/enhancingperf.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ can be improved by passing an ``np.ndarray``.
184184
...: cpdef np.ndarray[double] apply_integrate_f(np.ndarray col_a, np.ndarray col_b,
185185
...: np.ndarray col_N):
186186
...: assert (col_a.dtype == np.float64
187-
...: and col_b.dtype == np.float64 and col_N.dtype == np.int_)
187+
...: and col_b.dtype == np.float64 and col_N.dtype == np.dtype(int))
188188
...: cdef Py_ssize_t i, n = len(col_N)
189189
...: assert (len(col_a) == len(col_b) == n)
190190
...: cdef np.ndarray[double] res = np.empty(n)

pandas/compat/numpy/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121
)
2222

2323

24+
np_long: type
25+
np_ulong: type
26+
27+
if _nlv >= Version("2.0.0.dev0"):
28+
try:
29+
np_long = np.long # type: ignore[attr-defined]
30+
np_ulong = np.ulong # type: ignore[attr-defined]
31+
except AttributeError:
32+
np_long = np.int_
33+
np_ulong = np.uint
34+
else:
35+
np_long = np.int_
36+
np_ulong = np.uint
37+
38+
2439
__all__ = [
2540
"np",
2641
"_np_version",

pandas/core/algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ def safe_sort(
16411641
else:
16421642
mask = None
16431643
else:
1644-
reverse_indexer = np.empty(len(sorter), dtype=np.int_)
1644+
reverse_indexer = np.empty(len(sorter), dtype=int)
16451645
reverse_indexer.put(sorter, np.arange(len(sorter)))
16461646
# Out of bound indices will be masked with `-1` next, so we
16471647
# may deal with them here without performance loss using `mode='wrap'`

pandas/tests/arrays/boolean/test_reduction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
import pandas as pd
5+
from pandas.compat.numpy import np_long
56

67

78
@pytest.fixture
@@ -51,7 +52,7 @@ def test_reductions_return_types(dropna, data, all_numeric_reductions):
5152
s = s.dropna()
5253

5354
if op in ("sum", "prod"):
54-
assert isinstance(getattr(s, op)(), np.int_)
55+
assert isinstance(getattr(s, op)(), np_long)
5556
elif op == "count":
5657
# Oddly on the 32 bit build (but not Windows), this is intc (!= intp)
5758
assert isinstance(getattr(s, op)(), np.integer)

pandas/tests/dtypes/cast/test_infer_dtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_infer_dtype_from_scalar(value, expected):
170170
@pytest.mark.parametrize(
171171
"arr, expected",
172172
[
173-
([1], np.int_),
173+
([1], np.dtype(int)),
174174
(np.array([1], dtype=np.int64), np.int64),
175175
([np.nan, 1, ""], np.object_),
176176
(np.array([[1.0, 2.0]]), np.float64),

pandas/tests/extension/base/dim2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def get_reduction_result_dtype(dtype):
248248
return NUMPY_INT_TO_DTYPE[np.dtype(int)]
249249
else:
250250
# i.e. dtype.kind == "u"
251-
return NUMPY_INT_TO_DTYPE[np.dtype(np.uint)]
251+
return NUMPY_INT_TO_DTYPE[np.dtype("uint")]
252252

253253
if method in ["sum", "prod"]:
254254
# std and var are not dtype-preserving

pandas/tests/frame/indexing/test_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ def test_setitem_list(self, float_frame):
108108
data["A"] = newcolumndata
109109

110110
def test_setitem_list2(self):
111-
df = DataFrame(0, index=range(3), columns=["tt1", "tt2"], dtype=np.int_)
111+
df = DataFrame(0, index=range(3), columns=["tt1", "tt2"], dtype=int)
112112
df.loc[1, ["tt1", "tt2"]] = [1, 2]
113113

114114
result = df.loc[df.index[1], ["tt1", "tt2"]]
115-
expected = Series([1, 2], df.columns, dtype=np.int_, name=1)
115+
expected = Series([1, 2], df.columns, dtype=int, name=1)
116116
tm.assert_series_equal(result, expected)
117117

118118
df["tt1"] = df["tt2"] = "0"

pandas/tests/frame/methods/test_shift.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
offsets,
1515
)
1616
import pandas._testing as tm
17+
from pandas.compat.numpy import np_long
1718

1819

1920
class TestDataFrameShift:
@@ -471,22 +472,22 @@ def test_shift_axis1_multiple_blocks_with_int_fill(self):
471472
df1 = DataFrame(rng.integers(1000, size=(5, 3), dtype=int))
472473
df2 = DataFrame(rng.integers(1000, size=(5, 2), dtype=int))
473474
df3 = pd.concat([df1.iloc[:4, 1:3], df2.iloc[:4, :]], axis=1)
474-
result = df3.shift(2, axis=1, fill_value=np.int_(0))
475+
result = df3.shift(2, axis=1, fill_value=np_long(0))
475476
assert len(df3._mgr.blocks) == 2
476477

477478
expected = df3.take([-1, -1, 0, 1], axis=1)
478-
expected.iloc[:, :2] = np.int_(0)
479+
expected.iloc[:, :2] = np_long(0)
479480
expected.columns = df3.columns
480481

481482
tm.assert_frame_equal(result, expected)
482483

483484
# Case with periods < 0
484485
df3 = pd.concat([df1.iloc[:4, 1:3], df2.iloc[:4, :]], axis=1)
485-
result = df3.shift(-2, axis=1, fill_value=np.int_(0))
486+
result = df3.shift(-2, axis=1, fill_value=np_long(0))
486487
assert len(df3._mgr.blocks) == 2
487488

488489
expected = df3.take([2, 3, -1, -1], axis=1)
489-
expected.iloc[:, -2:] = np.int_(0)
490+
expected.iloc[:, -2:] = np_long(0)
490491
expected.columns = df3.columns
491492

492493
tm.assert_frame_equal(result, expected)

pandas/tests/frame/test_constructors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ def test_constructor_single_value(self):
18231823
DataFrame("a", [1, 2], ["a", "c"], float)
18241824

18251825
def test_constructor_with_datetimes(self):
1826-
intname = np.dtype(np.int_).name
1826+
intname = np.dtype(int).name
18271827
floatname = np.dtype(np.float64).name
18281828
objectname = np.dtype(np.object_).name
18291829

pandas/tests/frame/test_reductions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
algorithms,
3232
nanops,
3333
)
34+
from pandas.compat.numpy import np_long, np_ulong
35+
3436

3537
is_windows_or_is32 = is_platform_windows() or not IS64
3638

@@ -1700,11 +1702,11 @@ class TestEmptyDataFrameReductions:
17001702
"opname, dtype, exp_value, exp_dtype",
17011703
[
17021704
("sum", np.int8, 0, np.int64),
1703-
("prod", np.int8, 1, np.int_),
1705+
("prod", np.int8, 1, np_long),
17041706
("sum", np.int64, 0, np.int64),
17051707
("prod", np.int64, 1, np.int64),
17061708
("sum", np.uint8, 0, np.uint64),
1707-
("prod", np.uint8, 1, np.uint),
1709+
("prod", np.uint8, 1, np_ulong),
17081710
("sum", np.uint64, 0, np.uint64),
17091711
("prod", np.uint64, 1, np.uint64),
17101712
("sum", np.float32, 0, np.float32),

0 commit comments

Comments
 (0)