Skip to content

Commit b9e18c4

Browse files
committed
Revert "MAINT: Remove np.int_ and np.uint (pandas-dev#55369)"
This reverts commit 4976b69.
1 parent 895cff2 commit b9e18c4

29 files changed

+47
-79
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.dtype(int))
187+
...: and col_b.dtype == np.float64 and col_N.dtype == np.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: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,6 @@
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-
3924
__all__ = [
4025
"np",
4126
"_np_version",

pandas/core/algorithms.py

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

pandas/tests/arrays/boolean/test_reduction.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat.numpy import np_long
5-
64
import pandas as pd
75

86

@@ -53,7 +51,7 @@ def test_reductions_return_types(dropna, data, all_numeric_reductions):
5351
s = s.dropna()
5452

5553
if op in ("sum", "prod"):
56-
assert isinstance(getattr(s, op)(), np_long)
54+
assert isinstance(getattr(s, op)(), np.int_)
5755
elif op == "count":
5856
# Oddly on the 32 bit build (but not Windows), this is intc (!= intp)
5957
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.dtype(int)),
173+
([1], np.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("uint")]
251+
return NUMPY_INT_TO_DTYPE[np.dtype(np.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=int)
111+
df = DataFrame(0, index=range(3), columns=["tt1", "tt2"], dtype=np.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=int, name=1)
115+
expected = Series([1, 2], df.columns, dtype=np.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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat.numpy import np_long
54
import pandas.util._test_decorators as td
65

76
import pandas as pd
@@ -472,22 +471,22 @@ def test_shift_axis1_multiple_blocks_with_int_fill(self):
472471
df1 = DataFrame(rng.integers(1000, size=(5, 3), dtype=int))
473472
df2 = DataFrame(rng.integers(1000, size=(5, 2), dtype=int))
474473
df3 = pd.concat([df1.iloc[:4, 1:3], df2.iloc[:4, :]], axis=1)
475-
result = df3.shift(2, axis=1, fill_value=np_long(0))
474+
result = df3.shift(2, axis=1, fill_value=np.int_(0))
476475
assert len(df3._mgr.blocks) == 2
477476

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

482481
tm.assert_frame_equal(result, expected)
483482

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

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

493492
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(int).name
1826+
intname = np.dtype(np.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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
IS64,
1111
is_platform_windows,
1212
)
13-
from pandas.compat.numpy import (
14-
np_long,
15-
np_ulong,
16-
)
1713
import pandas.util._test_decorators as td
1814

1915
import pandas as pd
@@ -1717,11 +1713,11 @@ class TestEmptyDataFrameReductions:
17171713
"opname, dtype, exp_value, exp_dtype",
17181714
[
17191715
("sum", np.int8, 0, np.int64),
1720-
("prod", np.int8, 1, np_long),
1716+
("prod", np.int8, 1, np.int_),
17211717
("sum", np.int64, 0, np.int64),
17221718
("prod", np.int64, 1, np.int64),
17231719
("sum", np.uint8, 0, np.uint64),
1724-
("prod", np.uint8, 1, np_ulong),
1720+
("prod", np.uint8, 1, np.uint),
17251721
("sum", np.uint64, 0, np.uint64),
17261722
("prod", np.uint64, 1, np.uint64),
17271723
("sum", np.float32, 0, np.float32),

pandas/tests/groupby/aggregate/test_cython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def test_cython_agg_empty_buckets_nanops(observed):
229229
# GH-18869 can't call nanops on empty groups, so hardcode expected
230230
# for these
231231
df = DataFrame([11, 12, 13], columns=["a"])
232-
grps = np.arange(0, 25, 5, dtype=int)
232+
grps = np.arange(0, 25, 5, dtype=np.int_)
233233
# add / sum
234234
result = df.groupby(pd.cut(df["a"], grps), observed=observed)._cython_agg_general(
235235
"sum", alt=None, numeric_only=True

pandas/tests/groupby/methods/test_quantile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def test_groupby_quantile_dt64tz_period():
468468
# Check that we match the group-by-group result
469469
exp = {i: df.iloc[i::5].quantile(0.5) for i in range(5)}
470470
expected = DataFrame(exp).T.infer_objects()
471-
expected.index = expected.index.astype(int)
471+
expected.index = expected.index.astype(np.int_)
472472

473473
tm.assert_frame_equal(result, expected)
474474

pandas/tests/groupby/methods/test_size.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_size_axis_1(df, axis_1, by, sort, dropna):
3939
if sort:
4040
expected = expected.sort_index()
4141
if is_integer_dtype(expected.index.dtype) and not any(x is None for x in by):
42-
expected.index = expected.index.astype(int)
42+
expected.index = expected.index.astype(np.int_)
4343

4444
msg = "DataFrame.groupby with axis=1 is deprecated"
4545
with tm.assert_produces_warning(FutureWarning, match=msg):

pandas/tests/groupby/methods/test_value_counts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ def test_mixed_groupings(normalize, expected_label, expected_values):
996996
result = gp.value_counts(sort=True, normalize=normalize)
997997
expected = DataFrame(
998998
{
999-
"level_0": np.array([4, 4, 5], dtype=int),
999+
"level_0": np.array([4, 4, 5], dtype=np.int_),
10001000
"A": [1, 1, 2],
10011001
"level_2": [8, 8, 7],
10021002
"B": [1, 3, 2],

pandas/tests/groupby/test_groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,12 +3001,12 @@ def test_groupby_reduce_period():
30013001

30023002
res = gb.max()
30033003
expected = ser[-10:]
3004-
expected.index = Index(range(10), dtype=int)
3004+
expected.index = Index(range(10), dtype=np.int_)
30053005
tm.assert_series_equal(res, expected)
30063006

30073007
res = gb.min()
30083008
expected = ser[:10]
3009-
expected.index = Index(range(10), dtype=int)
3009+
expected.index = Index(range(10), dtype=np.int_)
30103010
tm.assert_series_equal(res, expected)
30113011

30123012

pandas/tests/indexes/datetimes/test_datetime.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import numpy as np
77
import pytest
88

9-
from pandas.compat.numpy import np_long
10-
119
import pandas as pd
1210
from pandas import (
1311
DataFrame,
@@ -58,7 +56,7 @@ def test_time_overflow_for_32bit_machines(self):
5856
# (which has value 1e9) and since the max value for np.int32 is ~2e9,
5957
# and since those machines won't promote np.int32 to np.int64, we get
6058
# overflow.
61-
periods = np_long(1000)
59+
periods = np.int_(1000)
6260

6361
idx1 = date_range(start="2000", periods=periods, freq="s")
6462
assert len(idx1) == periods

pandas/tests/indexes/datetimes/test_indexing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import numpy as np
99
import pytest
1010

11-
from pandas.compat.numpy import np_long
12-
1311
import pandas as pd
1412
from pandas import (
1513
DatetimeIndex,
@@ -93,7 +91,7 @@ def test_dti_business_getitem(self, freq):
9391
assert fancy_indexed.freq is None
9492

9593
# 32-bit vs. 64-bit platforms
96-
assert rng[4] == rng[np_long(4)]
94+
assert rng[4] == rng[np.int_(4)]
9795

9896
@pytest.mark.parametrize("freq", ["B", "C"])
9997
def test_dti_business_getitem_matplotlib_hackaround(self, freq):

pandas/tests/indexes/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def test_fancy(self, simple_index):
457457
["string", "int64", "int32", "uint64", "uint32", "float64", "float32"],
458458
indirect=True,
459459
)
460-
@pytest.mark.parametrize("dtype", [int, np.bool_])
460+
@pytest.mark.parametrize("dtype", [np.int_, np.bool_])
461461
def test_empty_fancy(self, index, dtype):
462462
empty_arr = np.array([], dtype=dtype)
463463
empty_index = type(index)([], dtype=index.dtype)

pandas/tests/indexing/multiindex/test_partial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_getitem_intkey_leading_level(
166166
mi = ser.index
167167
assert isinstance(mi, MultiIndex)
168168
if dtype is int:
169-
assert mi.levels[0].dtype == np.dtype(int)
169+
assert mi.levels[0].dtype == np.int_
170170
else:
171171
assert mi.levels[0].dtype == np.float64
172172

pandas/tests/indexing/test_loc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def test_loc_to_fail(self):
442442
)
443443

444444
msg = (
445-
rf"\"None of \[Index\(\[1, 2\], dtype='{np.dtype(int)}'\)\] are "
445+
rf"\"None of \[Index\(\[1, 2\], dtype='{np.int_().dtype}'\)\] are "
446446
r"in the \[index\]\""
447447
)
448448
with pytest.raises(KeyError, match=msg):
@@ -460,7 +460,7 @@ def test_loc_to_fail2(self):
460460
s.loc[-1]
461461

462462
msg = (
463-
rf"\"None of \[Index\(\[-1, -2\], dtype='{np.dtype(int)}'\)\] are "
463+
rf"\"None of \[Index\(\[-1, -2\], dtype='{np.int_().dtype}'\)\] are "
464464
r"in the \[index\]\""
465465
)
466466
with pytest.raises(KeyError, match=msg):
@@ -476,7 +476,7 @@ def test_loc_to_fail2(self):
476476

477477
s["a"] = 2
478478
msg = (
479-
rf"\"None of \[Index\(\[-2\], dtype='{np.dtype(int)}'\)\] are "
479+
rf"\"None of \[Index\(\[-2\], dtype='{np.int_().dtype}'\)\] are "
480480
r"in the \[index\]\""
481481
)
482482
with pytest.raises(KeyError, match=msg):
@@ -493,7 +493,7 @@ def test_loc_to_fail3(self):
493493
df = DataFrame([["a"], ["b"]], index=[1, 2], columns=["value"])
494494

495495
msg = (
496-
rf"\"None of \[Index\(\[3\], dtype='{np.dtype(int)}'\)\] are "
496+
rf"\"None of \[Index\(\[3\], dtype='{np.int_().dtype}'\)\] are "
497497
r"in the \[index\]\""
498498
)
499499
with pytest.raises(KeyError, match=msg):
@@ -510,7 +510,7 @@ def test_loc_getitem_list_with_fail(self):
510510

511511
s.loc[[2]]
512512

513-
msg = f"\"None of [Index([3], dtype='{np.dtype(int)}')] are in the [index]"
513+
msg = f"\"None of [Index([3], dtype='{np.int_().dtype}')] are in the [index]"
514514
with pytest.raises(KeyError, match=re.escape(msg)):
515515
s.loc[[3]]
516516

@@ -1209,7 +1209,7 @@ def test_loc_setitem_empty_append_raises(self):
12091209
df = DataFrame(columns=["x", "y"])
12101210
df.index = df.index.astype(np.int64)
12111211
msg = (
1212-
rf"None of \[Index\(\[0, 1\], dtype='{np.dtype(int)}'\)\] "
1212+
rf"None of \[Index\(\[0, 1\], dtype='{np.int_().dtype}'\)\] "
12131213
r"are in the \[index\]"
12141214
)
12151215
with pytest.raises(KeyError, match=msg):

pandas/tests/indexing/test_partial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def test_series_partial_set(self):
402402

403403
# raises as nothing is in the index
404404
msg = (
405-
rf"\"None of \[Index\(\[3, 3, 3\], dtype='{np.dtype(int)}'\)\] "
405+
rf"\"None of \[Index\(\[3, 3, 3\], dtype='{np.int_().dtype}'\)\] "
406406
r"are in the \[index\]\""
407407
)
408408
with pytest.raises(KeyError, match=msg):
@@ -483,7 +483,7 @@ def test_series_partial_set_with_name(self):
483483

484484
# raises as nothing is in the index
485485
msg = (
486-
rf"\"None of \[Index\(\[3, 3, 3\], dtype='{np.dtype(int)}', "
486+
rf"\"None of \[Index\(\[3, 3, 3\], dtype='{np.int_().dtype}', "
487487
r"name='idx'\)\] are in the \[index\]\""
488488
)
489489
with pytest.raises(KeyError, match=msg):

pandas/tests/internals/test_internals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def test_set_change_dtype(self, mgr):
468468
np.random.default_rng(2).standard_normal(N).astype(int),
469469
)
470470
idx = mgr2.items.get_loc("quux")
471-
assert mgr2.iget(idx).dtype == np.dtype(int)
471+
assert mgr2.iget(idx).dtype == np.int_
472472

473473
mgr2.iset(
474474
mgr2.items.get_loc("quux"), np.random.default_rng(2).standard_normal(N)

pandas/tests/io/parser/test_parse_dates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_read_csv_with_custom_date_parser(all_parsers):
4747
# GH36111
4848
def __custom_date_parser(time):
4949
time = time.astype(np.float64)
50-
time = time.astype(int) # convert float seconds to int type
50+
time = time.astype(np.int_) # convert float seconds to int type
5151
return pd.to_timedelta(time, unit="s")
5252

5353
testdata = StringIO(
@@ -87,7 +87,7 @@ def test_read_csv_with_custom_date_parser_parse_dates_false(all_parsers):
8787
# GH44366
8888
def __custom_date_parser(time):
8989
time = time.astype(np.float64)
90-
time = time.astype(int) # convert float seconds to int type
90+
time = time.astype(np.int_) # convert float seconds to int type
9191
return pd.to_timedelta(time, unit="s")
9292

9393
testdata = StringIO(

pandas/tests/plotting/test_series.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import pytest
77

88
from pandas.compat import is_platform_linux
9-
from pandas.compat.numpy import (
10-
np_long,
11-
np_version_gte1p24,
12-
)
9+
from pandas.compat.numpy import np_version_gte1p24
1310
import pandas.util._test_decorators as td
1411

1512
import pandas as pd
@@ -564,7 +561,7 @@ def test_plot_fails_with_dupe_color_and_style(self):
564561
[
565562
["scott", 20],
566563
[None, 20],
567-
[None, np_long(20)],
564+
[None, np.int_(20)],
568565
[0.5, np.linspace(-100, 100, 20)],
569566
],
570567
)

0 commit comments

Comments
 (0)