From d7480311763eee512d1b351dfa7c84d6ff04b62c Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 2 Feb 2023 19:48:10 +0000 Subject: [PATCH] DEPR: Remove various uses of NumericIndex --- pandas/core/indexes/datetimes.py | 7 ++---- pandas/tests/dtypes/test_missing.py | 5 ++-- pandas/tests/groupby/test_pipe.py | 3 +-- pandas/tests/indexes/common.py | 19 ++++++-------- .../indexes/interval/test_constructors.py | 25 +++++++++---------- pandas/tests/indexes/test_base.py | 22 ++++++++-------- pandas/tests/indexes/test_common.py | 9 ++++--- pandas/tests/indexes/test_index_new.py | 7 +++--- pandas/tests/indexes/test_indexing.py | 3 +-- pandas/tests/indexing/test_floats.py | 5 ++-- 10 files changed, 47 insertions(+), 58 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index b2305d0fe1cbf..db5ebc6d6bef1 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -62,7 +62,6 @@ if TYPE_CHECKING: from pandas.core.api import ( DataFrame, - NumericIndex, PeriodIndex, ) @@ -283,11 +282,9 @@ def to_period(self, freq=None) -> PeriodIndex: return PeriodIndex._simple_new(arr, name=self.name) @doc(DatetimeArray.to_julian_date) - def to_julian_date(self) -> NumericIndex: - from pandas.core.indexes.api import NumericIndex - + def to_julian_date(self) -> Index: arr = self._data.to_julian_date() - return NumericIndex._simple_new(arr, name=self.name) + return Index._simple_new(arr, name=self.name) @doc(DatetimeArray.isocalendar) def isocalendar(self) -> DataFrame: diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index b9aa84aefd2cb..9be0b95472d99 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -41,7 +41,6 @@ date_range, ) import pandas._testing as tm -from pandas.core.api import NumericIndex fix_now = pd.Timestamp("2021-01-01") fix_utcnow = pd.Timestamp("2021-01-01", tz="UTC") @@ -406,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( - NumericIndex([0, np.nan]), NumericIndex([0, np.nan]), dtype_equal=dtype_equal + Index([0, np.nan]), Index([0, np.nan]), dtype_equal=dtype_equal ) assert not array_equivalent( - NumericIndex([0, np.nan]), NumericIndex([1, np.nan]), dtype_equal=dtype_equal + Index([0, np.nan]), Index([1, np.nan]), dtype_equal=dtype_equal ) assert array_equivalent( DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan]), dtype_equal=dtype_equal diff --git a/pandas/tests/groupby/test_pipe.py b/pandas/tests/groupby/test_pipe.py index 9eded607e8733..49ce51bedbf9f 100644 --- a/pandas/tests/groupby/test_pipe.py +++ b/pandas/tests/groupby/test_pipe.py @@ -6,7 +6,6 @@ Index, ) import pandas._testing as tm -from pandas.core.api import NumericIndex def test_pipe(): @@ -76,6 +75,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=NumericIndex([1, 2, 3], dtype=np.int64)) + expected = pd.Series([4, 8, 12], index=Index([1, 2, 3], dtype=np.int64)) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index c203792be2694..3ef4bb741f418 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -28,7 +28,6 @@ isna, ) import pandas._testing as tm -from pandas.core.api import NumericIndex from pandas.core.arrays import BaseMaskedArray @@ -317,9 +316,7 @@ def test_numpy_argsort(self, index): def test_repeat(self, simple_index): rep = 2 idx = simple_index.copy() - new_index_cls = ( - NumericIndex if isinstance(idx, RangeIndex) else idx._constructor - ) + new_index_cls = idx._constructor expected = new_index_cls(idx.values.repeat(rep), name=idx.name) tm.assert_index_equal(idx.repeat(rep), expected) @@ -523,7 +520,7 @@ def test_fillna(self, index): elif index.dtype == bool: # can't hold NAs return - elif isinstance(index, NumericIndex) and is_integer_dtype(index.dtype): + elif isinstance(index, Index) and is_integer_dtype(index.dtype): return elif isinstance(index, MultiIndex): idx = index.copy(deep=True) @@ -592,7 +589,7 @@ def test_map(self, simple_index): idx = simple_index result = idx.map(lambda x: x) - # RangeIndex are equivalent to the similar NumericIndex with int64 dtype + # RangeIndex are equivalent to the similar Index with int64 dtype tm.assert_index_equal(result, idx, exact="equiv") @pytest.mark.parametrize( @@ -615,7 +612,7 @@ def test_map_dictlike(self, mapper, simple_index): identity = mapper(idx.values, idx) result = idx.map(identity) - # RangeIndex are equivalent to the similar NumericIndex with int64 dtype + # RangeIndex are equivalent to the similar Index with int64 dtype tm.assert_index_equal(result, idx, exact="equiv") # empty mappable @@ -753,7 +750,7 @@ def test_index_groupby(self, simple_index): tm.assert_dict_equal(idx.groupby(to_groupby), expected) def test_append_preserves_dtype(self, simple_index): - # In particular NumericIndex with dtype float32 + # In particular Index with dtype float32 index = simple_index N = len(index) @@ -917,19 +914,19 @@ def test_arithmetic_explicit_conversions(self): # float conversions arr = np.arange(5, dtype="int64") * 3.2 - expected = NumericIndex(arr, dtype=np.float64) + expected = Index(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 = NumericIndex(arr, dtype=np.float64) + expected = Index(arr, dtype=np.float64) a = np.zeros(5, dtype="float64") result = fidx - a tm.assert_index_equal(result, expected) - expected = NumericIndex(-arr, dtype=np.float64) + expected = Index(-arr, dtype=np.float64) a = np.zeros(5, dtype="float64") result = a - fidx tm.assert_index_equal(result, expected) diff --git a/pandas/tests/indexes/interval/test_constructors.py b/pandas/tests/indexes/interval/test_constructors.py index e3f933a35efe7..4b46c6d612bae 100644 --- a/pandas/tests/indexes/interval/test_constructors.py +++ b/pandas/tests/indexes/interval/test_constructors.py @@ -18,7 +18,6 @@ timedelta_range, ) import pandas._testing as tm -from pandas.core.api import NumericIndex from pandas.core.arrays import IntervalArray import pandas.core.common as com @@ -39,9 +38,9 @@ class ConstructorTests: params=[ ([3, 14, 15, 92, 653], np.int64), (np.arange(10, dtype="int64"), np.int64), - (NumericIndex(np.arange(-10, 11, dtype=np.int64)), np.int64), - (NumericIndex(np.arange(10, 31, dtype=np.uint64)), np.uint64), - (NumericIndex(np.arange(20, 30, 0.5), dtype=np.float64), np.float64), + (Index(np.arange(-10, 11, dtype=np.int64)), np.int64), + (Index(np.arange(10, 31, dtype=np.uint64)), np.uint64), + (Index(np.arange(20, 30, 0.5), dtype=np.float64), np.float64), (date_range("20180101", periods=10), "