Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert np.int_ and np.uint changes #55505

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/user_guide/enhancingperf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ can be improved by passing an ``np.ndarray``.
...: cpdef np.ndarray[double] apply_integrate_f(np.ndarray col_a, np.ndarray col_b,
...: np.ndarray col_N):
...: assert (col_a.dtype == np.float64
...: and col_b.dtype == np.float64 and col_N.dtype == np.dtype(int))
...: and col_b.dtype == np.float64 and col_N.dtype == np.int_)
...: cdef Py_ssize_t i, n = len(col_N)
...: assert (len(col_a) == len(col_b) == n)
...: cdef np.ndarray[double] res = np.empty(n)
Expand Down
23 changes: 0 additions & 23 deletions pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
""" support numpy compatibility across versions """
import warnings

import numpy as np

from pandas.util.version import Version
Expand All @@ -23,27 +21,6 @@
)


np_long: type
np_ulong: type

if _nlv >= Version("2.0.0.dev0"):
try:
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
r".*In the future `np\.long` will be defined as.*",
FutureWarning,
)
np_long = np.long # type: ignore[attr-defined]
np_ulong = np.ulong # type: ignore[attr-defined]
except AttributeError:
np_long = np.int_
np_ulong = np.uint
else:
np_long = np.int_
np_ulong = np.uint


__all__ = [
"np",
"_np_version",
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ def safe_sort(
else:
mask = None
else:
reverse_indexer = np.empty(len(sorter), dtype=int)
reverse_indexer = np.empty(len(sorter), dtype=np.int_)
reverse_indexer.put(sorter, np.arange(len(sorter)))
# Out of bound indices will be masked with `-1` next, so we
# may deal with them here without performance loss using `mode='wrap'`
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/arrays/boolean/test_reduction.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

from pandas.compat.numpy import np_long

import pandas as pd


Expand Down Expand Up @@ -53,7 +51,7 @@ def test_reductions_return_types(dropna, data, all_numeric_reductions):
s = s.dropna()

if op in ("sum", "prod"):
assert isinstance(getattr(s, op)(), np_long)
assert isinstance(getattr(s, op)(), np.int_)
elif op == "count":
# Oddly on the 32 bit build (but not Windows), this is intc (!= intp)
assert isinstance(getattr(s, op)(), np.integer)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/cast/test_infer_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_infer_dtype_from_scalar(value, expected):
@pytest.mark.parametrize(
"arr, expected",
[
([1], np.dtype(int)),
([1], np.int_),
(np.array([1], dtype=np.int64), np.int64),
([np.nan, 1, ""], np.object_),
(np.array([[1.0, 2.0]]), np.float64),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/base/dim2.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def get_reduction_result_dtype(dtype):
return NUMPY_INT_TO_DTYPE[np.dtype(int)]
else:
# i.e. dtype.kind == "u"
return NUMPY_INT_TO_DTYPE[np.dtype("uint")]
return NUMPY_INT_TO_DTYPE[np.dtype(np.uint)]

if method in ["sum", "prod"]:
# std and var are not dtype-preserving
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ def test_setitem_list(self, float_frame):
data["A"] = newcolumndata

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

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

df["tt1"] = df["tt2"] = "0"
Expand Down
9 changes: 4 additions & 5 deletions pandas/tests/frame/methods/test_shift.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import pytest

from pandas.compat.numpy import np_long
import pandas.util._test_decorators as td

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

expected = df3.take([-1, -1, 0, 1], axis=1)
expected.iloc[:, :2] = np_long(0)
expected.iloc[:, :2] = np.int_(0)
expected.columns = df3.columns

tm.assert_frame_equal(result, expected)

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

expected = df3.take([2, 3, -1, -1], axis=1)
expected.iloc[:, -2:] = np_long(0)
expected.iloc[:, -2:] = np.int_(0)
expected.columns = df3.columns

tm.assert_frame_equal(result, expected)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ def test_constructor_single_value(self):
DataFrame("a", [1, 2], ["a", "c"], float)

def test_constructor_with_datetimes(self):
intname = np.dtype(int).name
intname = np.dtype(np.int_).name
floatname = np.dtype(np.float64).name
objectname = np.dtype(np.object_).name

Expand Down
8 changes: 2 additions & 6 deletions pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
IS64,
is_platform_windows,
)
from pandas.compat.numpy import (
np_long,
np_ulong,
)
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -1717,11 +1713,11 @@ class TestEmptyDataFrameReductions:
"opname, dtype, exp_value, exp_dtype",
[
("sum", np.int8, 0, np.int64),
("prod", np.int8, 1, np_long),
("prod", np.int8, 1, np.int_),
("sum", np.int64, 0, np.int64),
("prod", np.int64, 1, np.int64),
("sum", np.uint8, 0, np.uint64),
("prod", np.uint8, 1, np_ulong),
("prod", np.uint8, 1, np.uint),
("sum", np.uint64, 0, np.uint64),
("prod", np.uint64, 1, np.uint64),
("sum", np.float32, 0, np.float32),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/aggregate/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_cython_agg_empty_buckets_nanops(observed):
# GH-18869 can't call nanops on empty groups, so hardcode expected
# for these
df = DataFrame([11, 12, 13], columns=["a"])
grps = np.arange(0, 25, 5, dtype=int)
grps = np.arange(0, 25, 5, dtype=np.int_)
# add / sum
result = df.groupby(pd.cut(df["a"], grps), observed=observed)._cython_agg_general(
"sum", alt=None, numeric_only=True
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/methods/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def test_groupby_quantile_dt64tz_period():
# Check that we match the group-by-group result
exp = {i: df.iloc[i::5].quantile(0.5) for i in range(5)}
expected = DataFrame(exp).T.infer_objects()
expected.index = expected.index.astype(int)
expected.index = expected.index.astype(np.int_)

tm.assert_frame_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/methods/test_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_size_axis_1(df, axis_1, by, sort, dropna):
if sort:
expected = expected.sort_index()
if is_integer_dtype(expected.index.dtype) and not any(x is None for x in by):
expected.index = expected.index.astype(int)
expected.index = expected.index.astype(np.int_)

msg = "DataFrame.groupby with axis=1 is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/methods/test_value_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ def test_mixed_groupings(normalize, expected_label, expected_values):
result = gp.value_counts(sort=True, normalize=normalize)
expected = DataFrame(
{
"level_0": np.array([4, 4, 5], dtype=int),
"level_0": np.array([4, 4, 5], dtype=np.int_),
"A": [1, 1, 2],
"level_2": [8, 8, 7],
"B": [1, 3, 2],
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3001,12 +3001,12 @@ def test_groupby_reduce_period():

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

res = gb.min()
expected = ser[:10]
expected.index = Index(range(10), dtype=int)
expected.index = Index(range(10), dtype=np.int_)
tm.assert_series_equal(res, expected)


Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import numpy as np
import pytest

from pandas.compat.numpy import np_long

import pandas as pd
from pandas import (
DataFrame,
Expand Down Expand Up @@ -58,7 +56,7 @@ def test_time_overflow_for_32bit_machines(self):
# (which has value 1e9) and since the max value for np.int32 is ~2e9,
# and since those machines won't promote np.int32 to np.int64, we get
# overflow.
periods = np_long(1000)
periods = np.int_(1000)

idx1 = date_range(start="2000", periods=periods, freq="s")
assert len(idx1) == periods
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/indexes/datetimes/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import numpy as np
import pytest

from pandas.compat.numpy import np_long

import pandas as pd
from pandas import (
DatetimeIndex,
Expand Down Expand Up @@ -93,7 +91,7 @@ def test_dti_business_getitem(self, freq):
assert fancy_indexed.freq is None

# 32-bit vs. 64-bit platforms
assert rng[4] == rng[np_long(4)]
assert rng[4] == rng[np.int_(4)]

@pytest.mark.parametrize("freq", ["B", "C"])
def test_dti_business_getitem_matplotlib_hackaround(self, freq):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def test_fancy(self, simple_index):
["string", "int64", "int32", "uint64", "uint32", "float64", "float32"],
indirect=True,
)
@pytest.mark.parametrize("dtype", [int, np.bool_])
@pytest.mark.parametrize("dtype", [np.int_, np.bool_])
def test_empty_fancy(self, index, dtype):
empty_arr = np.array([], dtype=dtype)
empty_index = type(index)([], dtype=index.dtype)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/multiindex/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_getitem_intkey_leading_level(
mi = ser.index
assert isinstance(mi, MultiIndex)
if dtype is int:
assert mi.levels[0].dtype == np.dtype(int)
assert mi.levels[0].dtype == np.int_
else:
assert mi.levels[0].dtype == np.float64

Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def test_loc_to_fail(self):
)

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

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

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

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

s.loc[[2]]

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

Expand Down Expand Up @@ -1209,7 +1209,7 @@ def test_loc_setitem_empty_append_raises(self):
df = DataFrame(columns=["x", "y"])
df.index = df.index.astype(np.int64)
msg = (
rf"None of \[Index\(\[0, 1\], dtype='{np.dtype(int)}'\)\] "
rf"None of \[Index\(\[0, 1\], dtype='{np.int_().dtype}'\)\] "
r"are in the \[index\]"
)
with pytest.raises(KeyError, match=msg):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexing/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def test_series_partial_set(self):

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

# raises as nothing is in the index
msg = (
rf"\"None of \[Index\(\[3, 3, 3\], dtype='{np.dtype(int)}', "
rf"\"None of \[Index\(\[3, 3, 3\], dtype='{np.int_().dtype}', "
r"name='idx'\)\] are in the \[index\]\""
)
with pytest.raises(KeyError, match=msg):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def test_set_change_dtype(self, mgr):
np.random.default_rng(2).standard_normal(N).astype(int),
)
idx = mgr2.items.get_loc("quux")
assert mgr2.iget(idx).dtype == np.dtype(int)
assert mgr2.iget(idx).dtype == np.int_

mgr2.iset(
mgr2.items.get_loc("quux"), np.random.default_rng(2).standard_normal(N)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/parser/test_parse_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_read_csv_with_custom_date_parser(all_parsers):
# GH36111
def __custom_date_parser(time):
time = time.astype(np.float64)
time = time.astype(int) # convert float seconds to int type
time = time.astype(np.int_) # convert float seconds to int type
return pd.to_timedelta(time, unit="s")

testdata = StringIO(
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_read_csv_with_custom_date_parser_parse_dates_false(all_parsers):
# GH44366
def __custom_date_parser(time):
time = time.astype(np.float64)
time = time.astype(int) # convert float seconds to int type
time = time.astype(np.int_) # convert float seconds to int type
return pd.to_timedelta(time, unit="s")

testdata = StringIO(
Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import pytest

from pandas.compat import is_platform_linux
from pandas.compat.numpy import (
np_long,
np_version_gte1p24,
)
from pandas.compat.numpy import np_version_gte1p24
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -564,7 +561,7 @@ def test_plot_fails_with_dupe_color_and_style(self):
[
["scott", 20],
[None, 20],
[None, np_long(20)],
[None, np.int_(20)],
[0.5, np.linspace(-100, 100, 20)],
],
)
Expand Down
Loading
Loading