Skip to content

DEPR: Remove NumericIndex from pandas/_testing/ #51098

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
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ Other API changes
- 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`)
- Changed behavior of :meth:`Series.quantile` and :meth:`DataFrame.quantile` with :class:`SparseDtype` to retain sparse dtype (:issue:`49583`)
- 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`)
- :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`)
- :meth:`Series.unique` with dtype "timedelta64[ns]" or "datetime64[ns]" now returns :class:`TimedeltaArray` or :class:`DatetimeArray` instead of ``numpy.ndarray`` (:issue:`49176`)
- :func:`to_datetime` and :class:`DatetimeIndex` now allow sequences containing both ``datetime`` objects and numeric entries, matching :class:`Series` behavior (:issue:`49037`, :issue:`50453`)
- :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`)
Expand Down
11 changes: 5 additions & 6 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
use_numexpr,
with_csv_dialect,
)
from pandas.core.api import NumericIndex
from pandas.core.arrays import (
BaseMaskedArray,
ExtensionArray,
Expand Down Expand Up @@ -357,7 +356,7 @@ def makeBoolIndex(k: int = 10, name=None) -> Index:
return Index([False, True] + [False] * (k - 2), name=name)


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

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

return NumericIndex(values, dtype=dtype, name=name)
return Index(values, dtype=dtype, name=name)


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


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


def makeFloatIndex(k: int = 10, *, name=None, dtype: Dtype = "float64") -> NumericIndex:
def makeFloatIndex(k: int = 10, *, name=None, dtype: Dtype = "float64") -> Index:
dtype = pandas_dtype(dtype)
if not is_float_dtype(dtype):
raise TypeError(f"Wrong dtype {dtype}")
Expand Down
28 changes: 20 additions & 8 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def assert_almost_equal(
right : object
check_dtype : bool or {'equiv'}, default 'equiv'
Check dtype if both a and b are the same type. If 'equiv' is passed in,
then `RangeIndex` and `NumericIndex` with int64 dtype are also considered
then `RangeIndex` and `Index` with int64 dtype are also considered
equivalent when doing type checking.
rtol : float, default 1e-5
Relative tolerance.
Expand Down Expand Up @@ -197,7 +197,7 @@ def assert_index_equal(
exact : bool or {'equiv'}, default 'equiv'
Whether to check the Index class, dtype and inferred_type
are identical. If 'equiv', then RangeIndex can be substituted for
NumericIndex with an int64 dtype as well.
Index with an int64 dtype as well.
check_names : bool, default True
Whether to check the names attribute.
check_exact : bool, default True
Expand Down Expand Up @@ -348,8 +348,6 @@ def assert_class_equal(
"""
Checks classes are equal.
"""
from pandas.core.indexes.numeric import NumericIndex

__tracebackhide__ = True

def repr_class(x):
Expand All @@ -359,12 +357,26 @@ def repr_class(x):

return type(x).__name__

def is_class_equiv(idx: Index) -> bool:
"""Classes that are a RangeIndex (sub-)instance or exactly an `Index` .

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

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

if exact == "equiv":
# accept equivalence of NumericIndex (sub-)classes
if isinstance(left, NumericIndex) and isinstance(right, NumericIndex):
if is_class_equiv(left) and is_class_equiv(right):
return

msg = f"{obj} classes are different"
Expand Down Expand Up @@ -470,7 +482,7 @@ def assert_categorical_equal(
):
exact = "equiv"
else:
# We still want to require exact matches for NumericIndex
# We still want to require exact matches for Index
exact = True

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