Skip to content

DEPR: Remove NumericIndex #51139

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
merged 4 commits into from
Feb 3, 2023
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
9 changes: 1 addition & 8 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,7 @@ def is_class_equiv(idx: Index) -> bool:
This only checks class equivalence. There is a separate check that the
dtype is int64.
"""
from pandas.core.indexes.numeric import NumericIndex

if isinstance(idx, RangeIndex):
return True
elif type(idx) is Index or type(idx) is NumericIndex:
return True
else:
return False
return type(idx) is Index or isinstance(idx, RangeIndex)

if type(left) == type(right):
return
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,7 @@ def __init__(self, obj: DataFrame, n: int, keep: str, columns: IndexLabel) -> No
self.columns = columns

def compute(self, method: str) -> DataFrame:

from pandas.core.api import NumericIndex
from pandas.core.api import Index

n = self.n
frame = self.obj
Expand Down Expand Up @@ -1342,7 +1341,7 @@ def get_indexer(current_indexer, other_indexer):
original_index = frame.index
cur_frame = frame = frame.reset_index(drop=True)
cur_n = n
indexer = NumericIndex([], dtype=np.int64)
indexer = Index([], dtype=np.int64)

for i, column in enumerate(columns):
# For each column we apply method to cur_frame[column].
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
Index,
IntervalIndex,
MultiIndex,
NumericIndex,
PeriodIndex,
RangeIndex,
TimedeltaIndex,
Expand Down Expand Up @@ -117,7 +116,6 @@
"NaT",
"notna",
"notnull",
"NumericIndex",
"Period",
"PeriodDtype",
"PeriodIndex",
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ def factorize(
uniques = uniques.astype(np.float32)

if isinstance(self, ABCIndex):
# preserve e.g. NumericIndex, preserve MultiIndex
# preserve e.g. MultiIndex
uniques = self._constructor(uniques)
else:
from pandas import Index
Expand Down
1 change: 0 additions & 1 deletion pandas/core/dtypes/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def _subclasscheck(cls, inst) -> bool:
{
"index",
"rangeindex",
"numericindex",
"multiindex",
"datetimeindex",
"timedeltaindex",
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/indexes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.interval import IntervalIndex
from pandas.core.indexes.multi import MultiIndex
from pandas.core.indexes.numeric import NumericIndex
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.range import RangeIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
Expand All @@ -46,7 +45,6 @@
__all__ = [
"Index",
"MultiIndex",
"NumericIndex",
"CategoricalIndex",
"IntervalIndex",
"RangeIndex",
Expand Down
16 changes: 2 additions & 14 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ class Index(IndexOpsMixin, PandasObject):
DatetimeIndex : Index of datetime64 data.
TimedeltaIndex : Index of timedelta64 data.
PeriodIndex : Index of Period data.
NumericIndex : Index of numpy int/uint/float data.

Notes
-----
Expand Down Expand Up @@ -539,7 +538,6 @@ def __new__(

klass = cls._dtype_to_subclass(arr.dtype)

# _ensure_array _may_ be unnecessary once NumericIndex etc are gone
arr = klass._ensure_array(arr, arr.dtype, copy=False)
Copy link
Member

Choose a reason for hiding this comment

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

It's not unnecessary?

Copy link
Contributor Author

@topper-123 topper-123 Feb 3, 2023

Choose a reason for hiding this comment

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

I had to remove “NumericIndex” and had to decide what to do with comment and opted to delete it. IMO _ensure_array could be refactored, but so could a lot of other things in pandas and _ensure_array is not that bad anymore compared to other things, so doesn’t merit a comment In the code base IMO.

This was my reasoning, others could of course have made a different judgement call…So it’s not a strong opinion, and I’m fine with it being refactored, but also it not being refactored :-)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah no worries, just wasn't sure if this was still being True or not

return klass._simple_new(arr, name)

Expand Down Expand Up @@ -596,18 +594,11 @@ def _dtype_to_subclass(cls, dtype: DtypeObj):

return TimedeltaIndex

elif dtype.kind in ["i", "f", "u"]:
from pandas.core.api import NumericIndex

return NumericIndex

elif dtype.kind == "O":
# NB: assuming away MultiIndex
return Index

elif issubclass(
dtype.type, (str, bool, np.bool_, complex, np.complex64, np.complex128)
):
elif issubclass(dtype.type, str) or is_numeric_dtype(dtype):
return Index

raise NotImplementedError(dtype)
Expand Down Expand Up @@ -1207,10 +1198,6 @@ def __repr__(self) -> str_t:
Return a string representation for this object.
"""
klass_name = type(self).__name__
from pandas.core.indexes.numeric import NumericIndex

if type(self) is NumericIndex:
klass_name = "Index"
data = self._format_data()
attrs = self._format_attrs()
space = self._format_space()
Expand Down Expand Up @@ -5375,6 +5362,7 @@ def identical(self, other) -> bool:
for c in self._comparables
)
and type(self) == type(other)
and self.dtype == other.dtype
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously the index type could differentiate e.g. Index([1, 2, 3], dtype=object) and Index([1, 2, 3], dtype="int64") (the latter actually being a NumericIndex), but we now need to be more precise.

)

@final
Expand Down
7 changes: 0 additions & 7 deletions pandas/core/indexes/numeric.py

This file was deleted.

7 changes: 3 additions & 4 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@
Index,
maybe_extract_name,
)
from pandas.core.indexes.numeric import NumericIndex
from pandas.core.ops.common import unpack_zerodim_and_defer

_empty_range = range(0)


class RangeIndex(NumericIndex):
class RangeIndex(Index):
"""
Immutable Index implementing a monotonic integer range.

Expand Down Expand Up @@ -196,7 +195,7 @@ def _validate_dtype(cls, dtype: Dtype | None) -> None:
@cache_readonly
def _constructor(self) -> type[Index]: # type: ignore[override]
"""return the class to use for construction"""
return NumericIndex
return Index

# error: Signature of "_data" incompatible with supertype "Index"
@cache_readonly
Expand Down Expand Up @@ -408,7 +407,7 @@ def _shallow_copy(self, values, name: Hashable = no_default):
new_range = range(values[0], values[-1] + diff, diff)
return type(self)._simple_new(new_range, name=name)
else:
return NumericIndex._simple_new(values, name=name)
return self._constructor._simple_new(values, name=name)

def _view(self: RangeIndex) -> RangeIndex:
result = type(self)._simple_new(self._range, name=self._name)
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
>>> s = pd.Series(text_values, index=int_values)
>>> s.info()
<class 'pandas.core.series.Series'>
NumericIndex: 5 entries, 1 to 5
Index: 5 entries, 1 to 5
Series name: None
Non-Null Count Dtype
-------------- -----
Expand All @@ -177,7 +177,7 @@
>>> s.info(verbose=False)
<class 'pandas.core.series.Series'>
NumericIndex: 5 entries, 1 to 5
Index: 5 entries, 1 to 5
dtypes: object(1)
memory usage: 80.0+ bytes
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_getitem_setitem_float_labels(self, using_array_manager):

# positional slicing only via iloc!
msg = (
"cannot do positional indexing on NumericIndex with "
"cannot do positional indexing on Index with "
r"these indexers \[1.0\] of type float"
)
with pytest.raises(TypeError, match=msg):
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/indexes/multi/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def test_setting_names_from_levels_raises():
new.index.name = "bar"

assert pd.Index._no_setting_name is False
assert pd.core.api.NumericIndex._no_setting_name is False
assert pd.RangeIndex._no_setting_name is False


Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/indexes/numeric/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def float_index(self, dtype):
return self._index_cls([0.0, 2.5, 5.0, 7.5, 10.0], dtype=dtype)

def test_repr_roundtrip(self, index):
from pandas.core.api import NumericIndex # noqa: F401

tm.assert_index_equal(eval(repr(index)), index, exact=True)

def check_coerce(self, a, b, is_float_index=True):
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/indexes/test_any_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ def test_str(self, index):
# test the string repr
index.name = "foo"
assert "'foo'" in str(index)
if type(index).__name__ == "NumericIndex": # TODO: remove NumericIndex
return
assert type(index).__name__ in str(index)


Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
RangeIndex,
)
import pandas._testing as tm
from pandas.core.api import NumericIndex


class TestCommon:
Expand Down Expand Up @@ -431,7 +430,7 @@ def test_hasnans_isnans(self, index_flat):

if len(index) == 0:
return
elif isinstance(index, NumericIndex) and is_integer_dtype(index.dtype):
elif is_integer_dtype(index.dtype):
return
elif index.dtype == bool:
# values[1] = np.nan below casts to True!
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/resample/test_resample_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def test_selection_api_validation():
# non DatetimeIndex
msg = (
"Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, "
"but got an instance of 'NumericIndex'"
"but got an instance of 'Index'"
)
with pytest.raises(TypeError, match=msg):
df.resample("2D", level="v")
Expand Down