diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 881e83313ced5..993fefdc91aa0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5689,6 +5689,8 @@ def _should_fallback_to_positional(self) -> bool: """ Should an integer key be treated as positional? """ + if isinstance(self.dtype, np.dtype) and self.dtype.kind in ["i", "u", "f"]: + return False return not self._holds_integer() _index_shared_docs[ diff --git a/pandas/core/indexes/numeric.py b/pandas/core/indexes/numeric.py index d26f8c01dc786..8113b5ea2bb2a 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -1,33 +1,7 @@ from __future__ import annotations -import numpy as np - -from pandas._typing import Dtype -from pandas.util._decorators import ( - cache_readonly, - doc, -) - from pandas.core.indexes.base import Index class NumericIndex(Index): - def __new__( - cls, data=None, dtype: Dtype | None = None, copy: bool = False, name=None - ) -> NumericIndex: - # temporary scaffolding, will be removed soon. - if isinstance(data, list) and len(data) == 0: - data = np.array([], dtype=np.int64) - elif isinstance(data, range): - data = np.arange(data.start, data.stop, data.step, dtype=np.int64) - return super().__new__( - cls, data=data, dtype=dtype, copy=copy, name=name - ) # type: ignore[return-value] - - # ---------------------------------------------------------------- - # Indexing Methods - - @cache_readonly - @doc(Index._should_fallback_to_positional) - def _should_fallback_to_positional(self) -> bool: - return False + pass diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index d78da49c967ab..2e83fb642905e 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -486,7 +486,7 @@ def test_fancy(self, simple_index): @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)([]) + empty_index = type(index)([], dtype=index.dtype) assert index[[]].identical(empty_index) assert index[empty_arr].identical(empty_index) @@ -500,7 +500,7 @@ def test_empty_fancy_raises(self, index): # DatetimeIndex is excluded, because it overrides getitem and should # be tested separately. empty_farr = np.array([], dtype=np.float_) - empty_index = type(index)([]) + empty_index = type(index)([], dtype=index.dtype) assert index[[]].identical(empty_index) # np.ndarray only accepts ndarray of int & bool dtypes, so should Index