Skip to content

DEPR: remove some more Int/UInt/Float64Index from tests #50075

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

Merged
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
22 changes: 9 additions & 13 deletions pandas/tests/arithmetic/test_timedelta64.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
timedelta_range,
)
import pandas._testing as tm
from pandas.core.api import (
Float64Index,
Int64Index,
UInt64Index,
)
from pandas.core.api import NumericIndex
from pandas.tests.arithmetic.common import (
assert_invalid_addsub_type,
assert_invalid_comparison,
Expand Down Expand Up @@ -492,10 +488,10 @@ def test_addition_ops(self):
# random indexes
msg = "Addition/subtraction of integers and integer-arrays"
with pytest.raises(TypeError, match=msg):
tdi + Int64Index([1, 2, 3])
tdi + NumericIndex([1, 2, 3], dtype=np.int64)

# this is a union!
# pytest.raises(TypeError, lambda : Int64Index([1,2,3]) + tdi)
# pytest.raises(TypeError, lambda : Index([1,2,3]) + tdi)

result = tdi + dti # name will be reset
expected = DatetimeIndex(["20130102", NaT, "20130105"])
Expand Down Expand Up @@ -1508,9 +1504,9 @@ def test_tdi_mul_float_series(self, box_with_array):
"other",
[
np.arange(1, 11),
Int64Index(range(1, 11)),
UInt64Index(range(1, 11)),
Float64Index(range(1, 11)),
NumericIndex(np.arange(1, 11), np.int64),
NumericIndex(range(1, 11), np.uint64),
NumericIndex(range(1, 11), np.float64),
pd.RangeIndex(1, 11),
],
ids=lambda x: type(x).__name__,
Expand Down Expand Up @@ -1594,7 +1590,7 @@ def test_td64arr_div_tdlike_scalar(self, two_hours, box_with_array):
xbox = np.ndarray if box is pd.array else box

rng = timedelta_range("1 days", "10 days", name="foo")
expected = Float64Index((np.arange(10) + 1) * 12, name="foo")
expected = NumericIndex((np.arange(10) + 1) * 12, dtype=np.float64, name="foo")

rng = tm.box_expected(rng, box)
expected = tm.box_expected(expected, xbox)
Expand Down Expand Up @@ -1634,7 +1630,7 @@ def test_td64arr_div_tdlike_scalar_with_nat(self, two_hours, box_with_array):
xbox = np.ndarray if box is pd.array else box

rng = TimedeltaIndex(["1 days", NaT, "2 days"], name="foo")
expected = Float64Index([12, np.nan, 24], name="foo")
expected = NumericIndex([12, np.nan, 24], dtype=np.float64, name="foo")

rng = tm.box_expected(rng, box)
expected = tm.box_expected(expected, xbox)
Expand All @@ -1652,7 +1648,7 @@ def test_td64arr_div_td64_ndarray(self, box_with_array):
xbox = np.ndarray if box is pd.array else box

rng = TimedeltaIndex(["1 days", NaT, "2 days"])
expected = Float64Index([12, np.nan, 24])
expected = NumericIndex([12, np.nan, 24], dtype=np.float64)

rng = tm.box_expected(rng, box)
expected = tm.box_expected(expected, xbox)
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,6 @@ def test_is_timedelta(self):
assert is_timedelta64_ns_dtype(tdi)
assert is_timedelta64_ns_dtype(tdi.astype("timedelta64[ns]"))

# Conversion to Int64Index:
assert not is_timedelta64_ns_dtype(Index([], dtype=np.float64))
assert not is_timedelta64_ns_dtype(Index([], dtype=np.int64))

Expand Down
17 changes: 9 additions & 8 deletions pandas/tests/dtypes/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
import pandas as pd
from pandas import (
DatetimeIndex,
Index,
NaT,
Series,
TimedeltaIndex,
date_range,
)
import pandas._testing as tm
from pandas.core.api import Float64Index
from pandas.core.api import NumericIndex

fix_now = pd.Timestamp("2021-01-01")
fix_utcnow = pd.Timestamp("2021-01-01", tz="UTC")
Expand Down Expand Up @@ -355,7 +356,7 @@ def test_decimal(self):
tm.assert_series_equal(result, ~expected)

# index
idx = pd.Index(arr)
idx = Index(arr)
expected = np.array([False, True])
result = isna(idx)
tm.assert_numpy_array_equal(result, expected)
Expand Down Expand Up @@ -404,10 +405,10 @@ def test_array_equivalent(dtype_equal):
np.array(["a", "b", "c", "d"]), np.array(["e", "e"]), dtype_equal=dtype_equal
)
assert array_equivalent(
Float64Index([0, np.nan]), Float64Index([0, np.nan]), dtype_equal=dtype_equal
NumericIndex([0, np.nan]), NumericIndex([0, np.nan]), dtype_equal=dtype_equal
)
assert not array_equivalent(
Float64Index([0, np.nan]), Float64Index([1, np.nan]), dtype_equal=dtype_equal
NumericIndex([0, np.nan]), NumericIndex([1, np.nan]), dtype_equal=dtype_equal
)
assert array_equivalent(
DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan]), dtype_equal=dtype_equal
Expand Down Expand Up @@ -559,15 +560,15 @@ def test_array_equivalent_nested():

def test_array_equivalent_index_with_tuples():
# GH#48446
idx1 = pd.Index(np.array([(pd.NA, 4), (1, 1)], dtype="object"))
idx2 = pd.Index(np.array([(1, 1), (pd.NA, 4)], dtype="object"))
idx1 = Index(np.array([(pd.NA, 4), (1, 1)], dtype="object"))
idx2 = Index(np.array([(1, 1), (pd.NA, 4)], dtype="object"))
assert not array_equivalent(idx1, idx2)
assert not idx1.equals(idx2)
assert not array_equivalent(idx2, idx1)
assert not idx2.equals(idx1)

idx1 = pd.Index(np.array([(4, pd.NA), (1, 1)], dtype="object"))
idx2 = pd.Index(np.array([(1, 1), (4, pd.NA)], dtype="object"))
idx1 = Index(np.array([(4, pd.NA), (1, 1)], dtype="object"))
idx2 = Index(np.array([(1, 1), (4, pd.NA)], dtype="object"))
assert not array_equivalent(idx1, idx2)
assert not idx1.equals(idx2)
assert not array_equivalent(idx2, idx1)
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
SparseArray,
TimedeltaArray,
)
from pandas.core.api import Int64Index

MIXED_FLOAT_DTYPES = ["float16", "float32", "float64"]
MIXED_INT_DTYPES = [
Expand Down Expand Up @@ -626,7 +625,7 @@ def test_constructor_2d_index(self):
df = DataFrame([[1]], columns=[[1]], index=[1, 2])
expected = DataFrame(
[1, 1],
index=Int64Index([1, 2], dtype="int64"),
index=Index([1, 2], dtype="int64"),
columns=MultiIndex(levels=[[1]], codes=[[0]]),
)
tm.assert_frame_equal(df, expected)
Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
bdate_range,
)
import pandas._testing as tm
from pandas.core.api import Int64Index
from pandas.tests.groupby import get_groupby_method_args


Expand Down Expand Up @@ -799,11 +798,9 @@ def test_apply_with_mixed_types():

def test_func_returns_object():
# GH 28652
df = DataFrame({"a": [1, 2]}, index=Int64Index([1, 2]))
df = DataFrame({"a": [1, 2]}, index=Index([1, 2]))
result = df.groupby("a").apply(lambda g: g.index)
expected = Series(
[Int64Index([1]), Int64Index([2])], index=Int64Index([1, 2], name="a")
)
expected = Series([Index([1]), Index([2])], index=Index([1, 2], name="a"))

tm.assert_series_equal(result, expected)

Expand Down
16 changes: 9 additions & 7 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
date_range,
)
import pandas._testing as tm
from pandas.core.api import (
Float64Index,
Int64Index,
)
from pandas.core.groupby.grouper import Grouping

# selection
Expand Down Expand Up @@ -691,11 +687,15 @@ def test_list_grouper_with_nat(self):
),
(
"agg",
Series(name=2, dtype=np.float64, index=Float64Index([], name=1)),
Series(
name=2, dtype=np.float64, index=Index([], dtype=np.float64, name=1)
),
),
(
"apply",
Series(name=2, dtype=np.float64, index=Float64Index([], name=1)),
Series(
name=2, dtype=np.float64, index=Index([], dtype=np.float64, name=1)
),
),
],
)
Expand Down Expand Up @@ -759,7 +759,9 @@ def test_groupby_multiindex_level_empty(self):
empty = df[df.value < 0]
result = empty.groupby("id").sum()
expected = DataFrame(
dtype="float64", columns=["value"], index=Int64Index([], name="id")
dtype="float64",
columns=["value"],
index=Index([], dtype=np.int64, name="id"),
)
tm.assert_frame_equal(result, expected)

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/groupby/test_min_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Series,
)
import pandas._testing as tm
from pandas.core.api import Int64Index


def test_max_min_non_numeric():
Expand Down Expand Up @@ -123,7 +122,7 @@ def test_groupby_aggregate_period_column(func):
df = DataFrame({"a": groups, "b": periods})

result = getattr(df.groupby("a")["b"], func)()
idx = Int64Index([1, 2], name="a")
idx = Index([1, 2], name="a")
expected = Series(periods, index=idx, name="b")

tm.assert_series_equal(result, expected)
Expand All @@ -137,7 +136,7 @@ def test_groupby_aggregate_period_frame(func):
df = DataFrame({"a": groups, "b": periods})

result = getattr(df.groupby("a"), func)()
idx = Int64Index([1, 2], name="a")
idx = Index([1, 2], name="a")
expected = DataFrame({"b": periods}, index=idx)

tm.assert_frame_equal(result, expected)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/groupby/test_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Index,
)
import pandas._testing as tm
from pandas.core.api import Int64Index
from pandas.core.api import NumericIndex


def test_pipe():
Expand Down Expand Up @@ -76,6 +76,6 @@ def h(df, arg3):
ser = pd.Series([1, 1, 2, 2, 3, 3])
result = ser.groupby(ser).pipe(lambda grp: grp.sum() * grp.count())

expected = pd.Series([4, 8, 12], index=Int64Index([1, 2, 3]))
expected = pd.Series([4, 8, 12], index=NumericIndex([1, 2, 3], dtype=np.int64))

tm.assert_series_equal(result, expected)
Loading