Skip to content

Commit 1acdf4b

Browse files
authored
DEPR: Remove NumericIndex from pandas/_testing/ (#51098)
* DEPR: Remove NumericIndex from pandas/_testing/ * add GH-number
1 parent 785691e commit 1acdf4b

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ Other API changes
708708
- The ``other`` argument in :meth:`DataFrame.mask` and :meth:`Series.mask` now defaults to ``no_default`` instead of ``np.nan`` consistent with :meth:`DataFrame.where` and :meth:`Series.where`. Entries will be filled with the corresponding NULL value (``np.nan`` for numpy dtypes, ``pd.NA`` for extension dtypes). (:issue:`49111`)
709709
- Changed behavior of :meth:`Series.quantile` and :meth:`DataFrame.quantile` with :class:`SparseDtype` to retain sparse dtype (:issue:`49583`)
710710
- When creating a :class:`Series` with a object-dtype :class:`Index` of datetime objects, pandas no longer silently converts the index to a :class:`DatetimeIndex` (:issue:`39307`, :issue:`23598`)
711+
- :func:`pandas.testing.assert_index_equal` with parameter ``exact="equiv"`` now considers two indexes equal when both are either a :class:`RangeIndex` or :class:`Index` with an ``int64`` dtype. Previously it meant either a :class:`RangeIndex` or a :class:`Int64Index` (:issue:`51098`)
711712
- :meth:`Series.unique` with dtype "timedelta64[ns]" or "datetime64[ns]" now returns :class:`TimedeltaArray` or :class:`DatetimeArray` instead of ``numpy.ndarray`` (:issue:`49176`)
712713
- :func:`to_datetime` and :class:`DatetimeIndex` now allow sequences containing both ``datetime`` objects and numeric entries, matching :class:`Series` behavior (:issue:`49037`, :issue:`50453`)
713714
- :func:`pandas.api.dtypes.is_string_dtype` now only returns ``True`` for array-likes with ``dtype=object`` when the elements are inferred to be strings (:issue:`15585`)

pandas/_testing/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
use_numexpr,
109109
with_csv_dialect,
110110
)
111-
from pandas.core.api import NumericIndex
112111
from pandas.core.arrays import (
113112
BaseMaskedArray,
114113
ExtensionArray,
@@ -357,7 +356,7 @@ def makeBoolIndex(k: int = 10, name=None) -> Index:
357356
return Index([False, True] + [False] * (k - 2), name=name)
358357

359358

360-
def makeNumericIndex(k: int = 10, *, name=None, dtype: Dtype | None) -> NumericIndex:
359+
def makeNumericIndex(k: int = 10, *, name=None, dtype: Dtype | None) -> Index:
361360
dtype = pandas_dtype(dtype)
362361
assert isinstance(dtype, np.dtype)
363362

@@ -372,17 +371,17 @@ def makeNumericIndex(k: int = 10, *, name=None, dtype: Dtype | None) -> NumericI
372371
else:
373372
raise NotImplementedError(f"wrong dtype {dtype}")
374373

375-
return NumericIndex(values, dtype=dtype, name=name)
374+
return Index(values, dtype=dtype, name=name)
376375

377376

378-
def makeIntIndex(k: int = 10, *, name=None, dtype: Dtype = "int64") -> NumericIndex:
377+
def makeIntIndex(k: int = 10, *, name=None, dtype: Dtype = "int64") -> Index:
379378
dtype = pandas_dtype(dtype)
380379
if not is_signed_integer_dtype(dtype):
381380
raise TypeError(f"Wrong dtype {dtype}")
382381
return makeNumericIndex(k, name=name, dtype=dtype)
383382

384383

385-
def makeUIntIndex(k: int = 10, *, name=None, dtype: Dtype = "uint64") -> NumericIndex:
384+
def makeUIntIndex(k: int = 10, *, name=None, dtype: Dtype = "uint64") -> Index:
386385
dtype = pandas_dtype(dtype)
387386
if not is_unsigned_integer_dtype(dtype):
388387
raise TypeError(f"Wrong dtype {dtype}")
@@ -393,7 +392,7 @@ def makeRangeIndex(k: int = 10, name=None, **kwargs) -> RangeIndex:
393392
return RangeIndex(0, k, 1, name=name, **kwargs)
394393

395394

396-
def makeFloatIndex(k: int = 10, *, name=None, dtype: Dtype = "float64") -> NumericIndex:
395+
def makeFloatIndex(k: int = 10, *, name=None, dtype: Dtype = "float64") -> Index:
397396
dtype = pandas_dtype(dtype)
398397
if not is_float_dtype(dtype):
399398
raise TypeError(f"Wrong dtype {dtype}")

pandas/_testing/asserters.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def assert_almost_equal(
7575
right : object
7676
check_dtype : bool or {'equiv'}, default 'equiv'
7777
Check dtype if both a and b are the same type. If 'equiv' is passed in,
78-
then `RangeIndex` and `NumericIndex` with int64 dtype are also considered
78+
then `RangeIndex` and `Index` with int64 dtype are also considered
7979
equivalent when doing type checking.
8080
rtol : float, default 1e-5
8181
Relative tolerance.
@@ -197,7 +197,7 @@ def assert_index_equal(
197197
exact : bool or {'equiv'}, default 'equiv'
198198
Whether to check the Index class, dtype and inferred_type
199199
are identical. If 'equiv', then RangeIndex can be substituted for
200-
NumericIndex with an int64 dtype as well.
200+
Index with an int64 dtype as well.
201201
check_names : bool, default True
202202
Whether to check the names attribute.
203203
check_exact : bool, default True
@@ -348,8 +348,6 @@ def assert_class_equal(
348348
"""
349349
Checks classes are equal.
350350
"""
351-
from pandas.core.indexes.numeric import NumericIndex
352-
353351
__tracebackhide__ = True
354352

355353
def repr_class(x):
@@ -359,12 +357,26 @@ def repr_class(x):
359357

360358
return type(x).__name__
361359

360+
def is_class_equiv(idx: Index) -> bool:
361+
"""Classes that are a RangeIndex (sub-)instance or exactly an `Index` .
362+
363+
This only checks class equivalence. There is a separate check that the
364+
dtype is int64.
365+
"""
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
374+
362375
if type(left) == type(right):
363376
return
364377

365378
if exact == "equiv":
366-
# accept equivalence of NumericIndex (sub-)classes
367-
if isinstance(left, NumericIndex) and isinstance(right, NumericIndex):
379+
if is_class_equiv(left) and is_class_equiv(right):
368380
return
369381

370382
msg = f"{obj} classes are different"
@@ -470,7 +482,7 @@ def assert_categorical_equal(
470482
):
471483
exact = "equiv"
472484
else:
473-
# We still want to require exact matches for NumericIndex
485+
# We still want to require exact matches for Index
474486
exact = True
475487

476488
if check_category_order:
@@ -511,7 +523,7 @@ def assert_interval_array_equal(
511523
exact : bool or {'equiv'}, default 'equiv'
512524
Whether to check the Index class, dtype and inferred_type
513525
are identical. If 'equiv', then RangeIndex can be substituted for
514-
NumericIndex with an int64 dtype as well.
526+
Index with an int64 dtype as well.
515527
obj : str, default 'IntervalArray'
516528
Specify object name being compared, internally used to show appropriate
517529
assertion message

0 commit comments

Comments
 (0)