Skip to content

DEPR: remove Int/Uint/Float64Index from pandas/tests/indexing & pandas/tests/series #50781

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
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
from pandas.core.indexes.api import (
DatetimeIndex,
Float64Index,
Index,
MultiIndex,
PeriodIndex,
Expand Down Expand Up @@ -2572,7 +2571,8 @@ def quantile(

if is_list_like(q):
result.name = self.name
return self._constructor(result, index=Float64Index(q), name=self.name)
idx = Index(q, dtype=np.float64)
return self._constructor(result, index=idx, name=self.name)
else:
# scalar
return result.iloc[0]
Expand Down
13 changes: 7 additions & 6 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
is_datetime64_dtype,
is_datetime64tz_dtype,
is_extension_array_dtype,
is_integer_dtype,
is_list_like,
is_string_dtype,
is_timedelta64_dtype,
Expand All @@ -88,7 +89,7 @@
concat,
isna,
)
from pandas.core.api import Int64Index
from pandas.core.api import NumericIndex
from pandas.core.arrays import (
Categorical,
DatetimeArray,
Expand Down Expand Up @@ -2242,13 +2243,13 @@ class GenericIndexCol(IndexCol):
def is_indexed(self) -> bool:
return False

# error: Return type "Tuple[Int64Index, Int64Index]" of "convert"
# error: Return type "Tuple[NumericIndex, NumericIndex]" of "convert"
# incompatible with return type "Union[Tuple[ndarray[Any, Any],
# ndarray[Any, Any]], Tuple[DatetimeIndex, DatetimeIndex]]" in
# supertype "IndexCol"
def convert( # type: ignore[override]
self, values: np.ndarray, nan_rep, encoding: str, errors: str
) -> tuple[Int64Index, Int64Index]:
) -> tuple[NumericIndex, NumericIndex]:
"""
Convert the data from this selection to the appropriate pandas type.

Expand All @@ -2261,7 +2262,7 @@ def convert( # type: ignore[override]
"""
assert isinstance(values, np.ndarray), type(values)

index = Int64Index(np.arange(len(values)))
index = NumericIndex(np.arange(len(values)), dtype=np.int64)
return index, index

def set_attr(self) -> None:
Expand Down Expand Up @@ -4864,11 +4865,11 @@ def _convert_index(name: str, index: Index, encoding: str, errors: str) -> Index
atom = DataIndexableCol._get_atom(converted)

if (
isinstance(index, Int64Index)
(isinstance(index, NumericIndex) and is_integer_dtype(index))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to exclude unsigned here? or non-64-bit?

Copy link
Contributor Author

@topper-123 topper-123 Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually makes no difference AFAIKS, because below in lines 4911:4914 there is a section for integers and floats, which returns the same IndexCol (because getattr(index, "freq", None) is None and the same for tz).

So I could either delete this line, or the section on line 4911-4914 or keep both, the result is the same. My opinion is that it would be cleanest to delete this line and handle numeric indexes in the section in lines 4911-4914.

or needs_i8_conversion(index.dtype)
or is_bool_dtype(index.dtype)
):
# Includes Int64Index, RangeIndex, DatetimeIndex, TimedeltaIndex, PeriodIndex,
# Includes NumericIndex, RangeIndex, DatetimeIndex, TimedeltaIndex, PeriodIndex,
# in which case "kind" is "integer", "integer", "datetime64",
# "timedelta64", and "integer", respectively.
return IndexCol(
Expand Down
22 changes: 9 additions & 13 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
isna,
)
import pandas._testing as tm
from pandas.core.api import ( # noqa:F401
Float64Index,
Int64Index,
NumericIndex,
UInt64Index,
)
from pandas.core.api import NumericIndex
from pandas.core.arrays import BaseMaskedArray


Expand Down Expand Up @@ -322,7 +317,9 @@ def test_numpy_argsort(self, index):
def test_repeat(self, simple_index):
rep = 2
idx = simple_index.copy()
new_index_cls = Int64Index if isinstance(idx, RangeIndex) else idx._constructor
new_index_cls = (
NumericIndex if isinstance(idx, RangeIndex) else idx._constructor
)
expected = new_index_cls(idx.values.repeat(rep), name=idx.name)
tm.assert_index_equal(idx.repeat(rep), expected)

Expand Down Expand Up @@ -505,7 +502,6 @@ def test_equals_op(self, simple_index):
# assuming the 2nd to last item is unique in the data
item = index_a[-2]
tm.assert_numpy_array_equal(index_a == item, expected3)
# For RangeIndex we can convert to Int64Index
tm.assert_series_equal(series_a == item, Series(expected3))

def test_format(self, simple_index):
Expand Down Expand Up @@ -596,7 +592,7 @@ def test_map(self, simple_index):
idx = simple_index

result = idx.map(lambda x: x)
# For RangeIndex we convert to Int64Index
# RangeIndex are equivalent to the similar NumericIndex with int64 dtype
tm.assert_index_equal(result, idx, exact="equiv")

@pytest.mark.parametrize(
Expand All @@ -619,7 +615,7 @@ def test_map_dictlike(self, mapper, simple_index):
identity = mapper(idx.values, idx)

result = idx.map(identity)
# For RangeIndex we convert to Int64Index
# RangeIndex are equivalent to the similar NumericIndex with int64 dtype
tm.assert_index_equal(result, idx, exact="equiv")

# empty mappable
Expand Down Expand Up @@ -910,19 +906,19 @@ def test_arithmetic_explicit_conversions(self):

# float conversions
arr = np.arange(5, dtype="int64") * 3.2
expected = Float64Index(arr)
expected = NumericIndex(arr, dtype=np.float64)
fidx = idx * 3.2
tm.assert_index_equal(fidx, expected)
fidx = 3.2 * idx
tm.assert_index_equal(fidx, expected)

# interops with numpy arrays
expected = Float64Index(arr)
expected = NumericIndex(arr, dtype=np.float64)
a = np.zeros(5, dtype="float64")
result = fidx - a
tm.assert_index_equal(result, expected)

expected = Float64Index(-arr)
expected = NumericIndex(-arr, dtype=np.float64)
a = np.zeros(5, dtype="float64")
result = a - fidx
tm.assert_index_equal(result, expected)
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/indexes/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Series,
array,
)
import pandas._testing as tm


@pytest.fixture(params=[None, False])
Expand Down Expand Up @@ -39,3 +40,22 @@ def listlike_box(request):
Types that may be passed as the indexer to searchsorted.
"""
return request.param


@pytest.fixture(
params=[
*tm.ALL_REAL_NUMPY_DTYPES,
"object",
"category",
"datetime64[ns]",
"timedelta64[ns]",
]
)
def any_numpy_dtype_for_small_pos_integer_indexes(request):
"""
Dtypes that can be given to an Index with small positive integers.

This means that for any dtype `x` in the params list, `Index([1, 2, 3], dtype=x)` is
valid and gives the correct Index (sub-)class.
"""
return request.param
3 changes: 1 addition & 2 deletions pandas/tests/indexes/datetimes/methods/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
date_range,
)
import pandas._testing as tm
from pandas.core.api import Int64Index


class TestDatetimeIndex:
Expand All @@ -30,7 +29,7 @@ def test_astype(self):
tm.assert_index_equal(result, expected)

result = idx.astype(np.int64)
expected = Int64Index(
expected = Index(
[1463356800000000000] + [-9223372036854775808] * 3,
dtype=np.int64,
name="idx",
Expand Down
11 changes: 5 additions & 6 deletions pandas/tests/indexes/datetimes/test_scalar_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
date_range,
)
import pandas._testing as tm
from pandas.core.api import Float64Index


class TestDatetimeIndexOps:
Expand Down Expand Up @@ -316,33 +315,33 @@ def test_1700(self):
dr = date_range(start=Timestamp("1710-10-01"), periods=5, freq="D")
r1 = pd.Index([x.to_julian_date() for x in dr])
r2 = dr.to_julian_date()
assert isinstance(r2, Float64Index)
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
tm.assert_index_equal(r1, r2)

def test_2000(self):
dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="D")
r1 = pd.Index([x.to_julian_date() for x in dr])
r2 = dr.to_julian_date()
assert isinstance(r2, Float64Index)
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
tm.assert_index_equal(r1, r2)

def test_hour(self):
dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="H")
r1 = pd.Index([x.to_julian_date() for x in dr])
r2 = dr.to_julian_date()
assert isinstance(r2, Float64Index)
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
tm.assert_index_equal(r1, r2)

def test_minute(self):
dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="T")
r1 = pd.Index([x.to_julian_date() for x in dr])
r2 = dr.to_julian_date()
assert isinstance(r2, Float64Index)
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
tm.assert_index_equal(r1, r2)

def test_second(self):
dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="S")
r1 = pd.Index([x.to_julian_date() for x in dr])
r2 = dr.to_julian_date()
assert isinstance(r2, Float64Index)
assert isinstance(r2, pd.Index) and r2.dtype == np.float64
tm.assert_index_equal(r1, r2)
3 changes: 1 addition & 2 deletions pandas/tests/indexes/datetimes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
date_range,
)
import pandas._testing as tm
from pandas.core.api import Int64Index

from pandas.tseries.offsets import (
BMonthEnd,
Expand Down Expand Up @@ -184,7 +183,7 @@ def test_union_dataframe_index(self):
tm.assert_index_equal(df.index, exp)

def test_union_with_DatetimeIndex(self, sort):
i1 = Int64Index(np.arange(0, 20, 2))
i1 = Index(np.arange(0, 20, 2, dtype=np.int64))
i2 = date_range(start="2012-01-03 00:00:00", periods=10, freq="D")
# Works
i1.union(i2, sort=sort)
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/interval/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

from pandas import (
DataFrame,
Index,
Interval,
IntervalIndex,
Series,
Timedelta,
Timestamp,
)
import pandas._testing as tm
from pandas.core.api import Float64Index


class TestIntervalIndexRendering:
Expand Down Expand Up @@ -54,8 +54,8 @@ def test_repr_floats(self):
[
Interval(left, right)
for left, right in zip(
Float64Index([329.973, 345.137], dtype="float64"),
Float64Index([345.137, 360.191], dtype="float64"),
Index([329.973, 345.137], dtype="float64"),
Index([345.137, 360.191], dtype="float64"),
)
]
),
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
timedelta_range,
)
import pandas._testing as tm
from pandas.core.api import Float64Index
import pandas.core.common as com


Expand Down Expand Up @@ -406,7 +405,7 @@ def test_maybe_convert_i8_nat(self, breaks):
index = IntervalIndex.from_breaks(breaks)

to_convert = breaks._constructor([pd.NaT] * 3)
expected = Float64Index([np.nan] * 3)
expected = Index([np.nan] * 3, dtype=np.float64)
result = index._maybe_convert_i8(to_convert)
tm.assert_index_equal(result, expected)

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/indexes/multi/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
period_range,
)
import pandas._testing as tm
from pandas.core.api import UInt64Index


def test_infer_objects(idx):
Expand Down Expand Up @@ -196,8 +195,8 @@ def test_map_dictlike(idx, mapper):

identity = mapper(idx.values, idx)

# we don't infer to UInt64 for a dict
if isinstance(idx, UInt64Index) and isinstance(identity, dict):
# we don't infer to uint64 dtype for a dict
if idx.dtype == np.uint64 and isinstance(identity, dict):
expected = idx.astype("int64")
else:
expected = idx
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/indexes/multi/test_integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import pandas as pd
from pandas import (
Index,
IntervalIndex,
MultiIndex,
RangeIndex,
)
import pandas._testing as tm
from pandas.core.api import Int64Index


def test_labels_dtypes():
Expand Down Expand Up @@ -84,17 +84,17 @@ def test_values_multiindex_periodindex():
idx = MultiIndex.from_arrays([ints, pidx])
result = idx.values

outer = Int64Index([x[0] for x in result])
tm.assert_index_equal(outer, Int64Index(ints))
outer = Index([x[0] for x in result])
tm.assert_index_equal(outer, Index(ints, dtype=np.int64))

inner = pd.PeriodIndex([x[1] for x in result])
tm.assert_index_equal(inner, pidx)

# n_lev > n_lab
result = idx[:2].values

outer = Int64Index([x[0] for x in result])
tm.assert_index_equal(outer, Int64Index(ints[:2]))
outer = Index([x[0] for x in result])
tm.assert_index_equal(outer, Index(ints[:2], dtype=np.int64))

inner = pd.PeriodIndex([x[1] for x in result])
tm.assert_index_equal(inner, pidx[:2])
Expand Down Expand Up @@ -246,11 +246,11 @@ def test_rangeindex_fallback_coercion_bug():
tm.assert_frame_equal(df, expected, check_like=True)

result = df.index.get_level_values("fizz")
expected = Int64Index(np.arange(10), name="fizz").repeat(10)
expected = Index(np.arange(10, dtype=np.int64), name="fizz").repeat(10)
tm.assert_index_equal(result, expected)

result = df.index.get_level_values("buzz")
expected = Int64Index(np.tile(np.arange(10), 10), name="buzz")
expected = Index(np.tile(np.arange(10, dtype=np.int64), 10), name="buzz")
tm.assert_index_equal(result, expected)


Expand Down
8 changes: 2 additions & 6 deletions pandas/tests/indexes/period/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
period_range,
)
import pandas._testing as tm
from pandas.core.api import (
Float64Index,
Int64Index,
)

dti4 = date_range("2016-01-01", periods=4)
dti = dti4[:-1]
Expand Down Expand Up @@ -806,10 +802,10 @@ def test_asof_locs_mismatched_type(self):

msg = "must be DatetimeIndex or PeriodIndex"
with pytest.raises(TypeError, match=msg):
pi.asof_locs(Int64Index(pi.asi8), mask)
pi.asof_locs(pd.Index(pi.asi8, dtype=np.int64), mask)

with pytest.raises(TypeError, match=msg):
pi.asof_locs(Float64Index(pi.asi8), mask)
pi.asof_locs(pd.Index(pi.asi8, dtype=np.float64), mask)

with pytest.raises(TypeError, match=msg):
# TimedeltaIndex
Expand Down
Loading