Skip to content

Commit 8cb6382

Browse files
authored
DEPR: Remove NumericIndex (#51139)
1 parent b65551c commit 8cb6382

File tree

16 files changed

+14
-53
lines changed

16 files changed

+14
-53
lines changed

pandas/_testing/asserters.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,7 @@ def is_class_equiv(idx: Index) -> bool:
363363
This only checks class equivalence. There is a separate check that the
364364
dtype is int64.
365365
"""
366-
from pandas.core.indexes.numeric import NumericIndex
367-
368-
if isinstance(idx, RangeIndex):
369-
return True
370-
elif type(idx) is Index or type(idx) is NumericIndex:
371-
return True
372-
else:
373-
return False
366+
return type(idx) is Index or isinstance(idx, RangeIndex)
374367

375368
if type(left) == type(right):
376369
return

pandas/core/algorithms.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,7 @@ def __init__(self, obj: DataFrame, n: int, keep: str, columns: IndexLabel) -> No
13131313
self.columns = columns
13141314

13151315
def compute(self, method: str) -> DataFrame:
1316-
1317-
from pandas.core.api import NumericIndex
1316+
from pandas.core.api import Index
13181317

13191318
n = self.n
13201319
frame = self.obj
@@ -1342,7 +1341,7 @@ def get_indexer(current_indexer, other_indexer):
13421341
original_index = frame.index
13431342
cur_frame = frame = frame.reset_index(drop=True)
13441343
cur_n = n
1345-
indexer = NumericIndex([], dtype=np.int64)
1344+
indexer = Index([], dtype=np.int64)
13461345

13471346
for i, column in enumerate(columns):
13481347
# For each column we apply method to cur_frame[column].

pandas/core/api.py

-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
Index,
5555
IntervalIndex,
5656
MultiIndex,
57-
NumericIndex,
5857
PeriodIndex,
5958
RangeIndex,
6059
TimedeltaIndex,
@@ -117,7 +116,6 @@
117116
"NaT",
118117
"notna",
119118
"notnull",
120-
"NumericIndex",
121119
"Period",
122120
"PeriodDtype",
123121
"PeriodIndex",

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ def factorize(
11611161
uniques = uniques.astype(np.float32)
11621162

11631163
if isinstance(self, ABCIndex):
1164-
# preserve e.g. NumericIndex, preserve MultiIndex
1164+
# preserve e.g. MultiIndex
11651165
uniques = self._constructor(uniques)
11661166
else:
11671167
from pandas import Index

pandas/core/dtypes/generic.py

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def _subclasscheck(cls, inst) -> bool:
9393
{
9494
"index",
9595
"rangeindex",
96-
"numericindex",
9796
"multiindex",
9897
"datetimeindex",
9998
"timedeltaindex",

pandas/core/indexes/api.py

-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from pandas.core.indexes.datetimes import DatetimeIndex
2727
from pandas.core.indexes.interval import IntervalIndex
2828
from pandas.core.indexes.multi import MultiIndex
29-
from pandas.core.indexes.numeric import NumericIndex
3029
from pandas.core.indexes.period import PeriodIndex
3130
from pandas.core.indexes.range import RangeIndex
3231
from pandas.core.indexes.timedeltas import TimedeltaIndex
@@ -46,7 +45,6 @@
4645
__all__ = [
4746
"Index",
4847
"MultiIndex",
49-
"NumericIndex",
5048
"CategoricalIndex",
5149
"IntervalIndex",
5250
"RangeIndex",

pandas/core/indexes/base.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ class Index(IndexOpsMixin, PandasObject):
317317
DatetimeIndex : Index of datetime64 data.
318318
TimedeltaIndex : Index of timedelta64 data.
319319
PeriodIndex : Index of Period data.
320-
NumericIndex : Index of numpy int/uint/float data.
321320
322321
Notes
323322
-----
@@ -539,7 +538,6 @@ def __new__(
539538

540539
klass = cls._dtype_to_subclass(arr.dtype)
541540

542-
# _ensure_array _may_ be unnecessary once NumericIndex etc are gone
543541
arr = klass._ensure_array(arr, arr.dtype, copy=False)
544542
return klass._simple_new(arr, name)
545543

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

597595
return TimedeltaIndex
598596

599-
elif dtype.kind in ["i", "f", "u"]:
600-
from pandas.core.api import NumericIndex
601-
602-
return NumericIndex
603-
604597
elif dtype.kind == "O":
605598
# NB: assuming away MultiIndex
606599
return Index
607600

608-
elif issubclass(
609-
dtype.type, (str, bool, np.bool_, complex, np.complex64, np.complex128)
610-
):
601+
elif issubclass(dtype.type, str) or is_numeric_dtype(dtype):
611602
return Index
612603

613604
raise NotImplementedError(dtype)
@@ -1207,10 +1198,6 @@ def __repr__(self) -> str_t:
12071198
Return a string representation for this object.
12081199
"""
12091200
klass_name = type(self).__name__
1210-
from pandas.core.indexes.numeric import NumericIndex
1211-
1212-
if type(self) is NumericIndex:
1213-
klass_name = "Index"
12141201
data = self._format_data()
12151202
attrs = self._format_attrs()
12161203
space = self._format_space()
@@ -5375,6 +5362,7 @@ def identical(self, other) -> bool:
53755362
for c in self._comparables
53765363
)
53775364
and type(self) == type(other)
5365+
and self.dtype == other.dtype
53785366
)
53795367

53805368
@final

pandas/core/indexes/numeric.py

-7
This file was deleted.

pandas/core/indexes/range.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@
4949
Index,
5050
maybe_extract_name,
5151
)
52-
from pandas.core.indexes.numeric import NumericIndex
5352
from pandas.core.ops.common import unpack_zerodim_and_defer
5453

5554
_empty_range = range(0)
5655

5756

58-
class RangeIndex(NumericIndex):
57+
class RangeIndex(Index):
5958
"""
6059
Immutable Index implementing a monotonic integer range.
6160
@@ -196,7 +195,7 @@ def _validate_dtype(cls, dtype: Dtype | None) -> None:
196195
@cache_readonly
197196
def _constructor(self) -> type[Index]: # type: ignore[override]
198197
"""return the class to use for construction"""
199-
return NumericIndex
198+
return Index
200199

201200
# error: Signature of "_data" incompatible with supertype "Index"
202201
@cache_readonly
@@ -408,7 +407,7 @@ def _shallow_copy(self, values, name: Hashable = no_default):
408407
new_range = range(values[0], values[-1] + diff, diff)
409408
return type(self)._simple_new(new_range, name=name)
410409
else:
411-
return NumericIndex._simple_new(values, name=name)
410+
return self._constructor._simple_new(values, name=name)
412411

413412
def _view(self: RangeIndex) -> RangeIndex:
414413
result = type(self)._simple_new(self._range, name=self._name)

pandas/io/formats/info.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
>>> s = pd.Series(text_values, index=int_values)
166166
>>> s.info()
167167
<class 'pandas.core.series.Series'>
168-
NumericIndex: 5 entries, 1 to 5
168+
Index: 5 entries, 1 to 5
169169
Series name: None
170170
Non-Null Count Dtype
171171
-------------- -----
@@ -177,7 +177,7 @@
177177
178178
>>> s.info(verbose=False)
179179
<class 'pandas.core.series.Series'>
180-
NumericIndex: 5 entries, 1 to 5
180+
Index: 5 entries, 1 to 5
181181
dtypes: object(1)
182182
memory usage: 80.0+ bytes
183183

pandas/tests/frame/indexing/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def test_getitem_setitem_float_labels(self, using_array_manager):
737737

738738
# positional slicing only via iloc!
739739
msg = (
740-
"cannot do positional indexing on NumericIndex with "
740+
"cannot do positional indexing on Index with "
741741
r"these indexers \[1.0\] of type float"
742742
)
743743
with pytest.raises(TypeError, match=msg):

pandas/tests/indexes/multi/test_names.py

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ def test_setting_names_from_levels_raises():
146146
new.index.name = "bar"
147147

148148
assert pd.Index._no_setting_name is False
149-
assert pd.core.api.NumericIndex._no_setting_name is False
150149
assert pd.RangeIndex._no_setting_name is False
151150

152151

pandas/tests/indexes/numeric/test_numeric.py

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def float_index(self, dtype):
4343
return self._index_cls([0.0, 2.5, 5.0, 7.5, 10.0], dtype=dtype)
4444

4545
def test_repr_roundtrip(self, index):
46-
from pandas.core.api import NumericIndex # noqa: F401
47-
4846
tm.assert_index_equal(eval(repr(index)), index, exact=True)
4947

5048
def check_coerce(self, a, b, is_float_index=True):

pandas/tests/indexes/test_any_index.py

-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ def test_str(self, index):
154154
# test the string repr
155155
index.name = "foo"
156156
assert "'foo'" in str(index)
157-
if type(index).__name__ == "NumericIndex": # TODO: remove NumericIndex
158-
return
159157
assert type(index).__name__ in str(index)
160158

161159

pandas/tests/indexes/test_common.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
RangeIndex,
3232
)
3333
import pandas._testing as tm
34-
from pandas.core.api import NumericIndex
3534

3635

3736
class TestCommon:
@@ -431,7 +430,7 @@ def test_hasnans_isnans(self, index_flat):
431430

432431
if len(index) == 0:
433432
return
434-
elif isinstance(index, NumericIndex) and is_integer_dtype(index.dtype):
433+
elif is_integer_dtype(index.dtype):
435434
return
436435
elif index.dtype == bool:
437436
# values[1] = np.nan below casts to True!

pandas/tests/resample/test_resample_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def test_selection_api_validation():
646646
# non DatetimeIndex
647647
msg = (
648648
"Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, "
649-
"but got an instance of 'NumericIndex'"
649+
"but got an instance of 'Index'"
650650
)
651651
with pytest.raises(TypeError, match=msg):
652652
df.resample("2D", level="v")

0 commit comments

Comments
 (0)