Skip to content

Commit abd7436

Browse files
API: hide NumericIndex from public top-level namespace in favor of pd.Index (#44819)
1 parent 3dfed3f commit abd7436

File tree

16 files changed

+41
-110
lines changed

16 files changed

+41
-110
lines changed

doc/source/reference/indexing.rst

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ Numeric Index
170170
:toctree: api/
171171
:template: autosummary/class_without_autosummary.rst
172172

173-
NumericIndex
174173
RangeIndex
175174
Int64Index
176175
UInt64Index

doc/source/user_guide/advanced.rst

+2-35
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,9 @@ Int64Index and RangeIndex
852852
~~~~~~~~~~~~~~~~~~~~~~~~~
853853

854854
.. deprecated:: 1.4.0
855-
In pandas 2.0, :class:`NumericIndex` will become the default index type for numeric types
855+
In pandas 2.0, :class:`Index` will become the default index type for numeric types
856856
instead of ``Int64Index``, ``Float64Index`` and ``UInt64Index`` and those index types
857857
are therefore deprecated and will be removed in a futire version.
858-
See :ref:`here <advanced.numericindex>` for more.
859858
``RangeIndex`` will not be removed, as it represents an optimized version of an integer index.
860859

861860
:class:`Int64Index` is a fundamental basic index in pandas. This is an immutable array
@@ -870,10 +869,9 @@ Float64Index
870869
~~~~~~~~~~~~
871870

872871
.. deprecated:: 1.4.0
873-
:class:`NumericIndex` will become the default index type for numeric types in the future
872+
:class:`Index` will become the default index type for numeric types in the future
874873
instead of ``Int64Index``, ``Float64Index`` and ``UInt64Index`` and those index types
875874
are therefore deprecated and will be removed in a future version of Pandas.
876-
See :ref:`here <advanced.numericindex>` for more.
877875
``RangeIndex`` will not be removed as it represents an optimized version of an integer index.
878876

879877
By default a :class:`Float64Index` will be automatically created when passing floating, or mixed-integer-floating values in index creation.
@@ -971,37 +969,6 @@ If you need integer based selection, you should use ``iloc``:
971969
dfir.iloc[0:5]
972970
973971
974-
.. _advanced.numericindex:
975-
976-
NumericIndex
977-
~~~~~~~~~~~~
978-
979-
.. versionadded:: 1.4.0
980-
981-
.. note::
982-
983-
In pandas 2.0, :class:`NumericIndex` will become the default index type for numeric types
984-
instead of :class:`Int64Index`, :class:`Float64Index` and :class:`UInt64Index` and those index types
985-
are therefore deprecated and will be removed in a future version.
986-
:class:`RangeIndex` will not be removed as it represents an optimized version of an integer index.
987-
988-
:class:`NumericIndex` is an index type that can hold data of any numpy int/uint/float dtype. For example:
989-
990-
.. ipython:: python
991-
992-
idx = pd.NumericIndex([1, 2, 4, 5], dtype="int8")
993-
idx
994-
ser = pd.Series(range(4), index=idx)
995-
ser
996-
997-
``NumericIndex`` works the same way as the existing ``Int64Index``, ``Float64Index`` and
998-
``UInt64Index`` except that it can hold any numpy int, uint or float dtype.
999-
1000-
Until Pandas 2.0, you will have to call ``NumericIndex`` explicitly in order to use it, like in the example above.
1001-
In the future, ``NumericIndex`` will become the default pandas numeric index type and will automatically be used where appropriate.
1002-
1003-
Please notice that ``NumericIndex`` *can not* hold Pandas numeric dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
1004-
1005972
.. _advanced.intervalindex:
1006973

1007974
IntervalIndex

doc/source/whatsnew/v0.16.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ When the function you wish to apply takes its data anywhere other than the first
6262
of ``(function, keyword)`` indicating where the DataFrame should flow. For example:
6363

6464
.. ipython:: python
65+
:okwarning:
6566
6667
import statsmodels.formula.api as sm
6768

doc/source/whatsnew/v1.4.0.rst

+25-53
Original file line numberDiff line numberDiff line change
@@ -40,55 +40,6 @@ This made it difficult to determine where the warning was being generated from.
4040
A value is trying to be set on a copy of a slice from a DataFrame.
4141

4242

43-
.. _whatsnew_140.enhancements.numeric_index:
44-
45-
More flexible numeric dtypes for indexes
46-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47-
48-
Until now, it has only been possible to create numeric indexes with int64/float64/uint64 dtypes.
49-
It is now possible to create an index of any numpy int/uint/float dtype using the new :class:`NumericIndex` index type (:issue:`41153`):
50-
51-
.. ipython:: python
52-
53-
pd.NumericIndex([1, 2, 3], dtype="int8")
54-
pd.NumericIndex([1, 2, 3], dtype="uint32")
55-
pd.NumericIndex([1, 2, 3], dtype="float32")
56-
57-
In order to maintain backwards compatibility, calls to the base :class:`Index` will currently
58-
return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`, where relevant.
59-
For example, the code below returns an ``Int64Index`` with dtype ``int64``:
60-
61-
.. code-block:: ipython
62-
63-
In [1]: pd.Index([1, 2, 3], dtype="int8")
64-
Int64Index([1, 2, 3], dtype='int64')
65-
66-
but will in a future version return a :class:`NumericIndex` with dtype ``int8``.
67-
68-
More generally, currently, all operations that until now have
69-
returned :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index` will
70-
continue to so. This means, that in order to use ``NumericIndex`` in the current version, you
71-
will have to call ``NumericIndex`` explicitly. For example the below series will have an ``Int64Index``:
72-
73-
.. code-block:: ipython
74-
75-
In [2]: ser = pd.Series([1, 2, 3], index=[1, 2, 3])
76-
In [3]: ser.index
77-
Int64Index([1, 2, 3], dtype='int64')
78-
79-
Instead, if you want to use a ``NumericIndex``, you should do:
80-
81-
.. ipython:: python
82-
83-
idx = pd.NumericIndex([1, 2, 3], dtype="int8")
84-
ser = pd.Series([1, 2, 3], index=idx)
85-
ser.index
86-
87-
In a future version of Pandas, :class:`NumericIndex` will become the default numeric index type and
88-
``Int64Index``, ``UInt64Index`` and ``Float64Index`` are therefore deprecated and will
89-
be removed in the future, see :ref:`here <whatsnew_140.deprecations.int64_uint64_float64index>` for more.
90-
91-
See :ref:`here <advanced.numericindex>` for more about :class:`NumericIndex`.
9243

9344

9445
.. _whatsnew_140.enhancements.ExtensionIndex:
@@ -541,12 +492,33 @@ Deprecations
541492

542493
Deprecated Int64Index, UInt64Index & Float64Index
543494
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
495+
544496
:class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index` have been deprecated
545-
in favor of the new :class:`NumericIndex` and will be removed in Pandas 2.0 (:issue:`43028`).
497+
in favor of the base :class:`Index` class and will be removed in Pandas 2.0 (:issue:`43028`).
498+
499+
For constructing a numeric index, you can use the base :class:`Index` class instead
500+
specifying the data type (which will also work on older pandas releases):
501+
502+
.. code-block:: python
503+
504+
# replace
505+
pd.Int64Index([1, 2, 3])
506+
# with
507+
pd.Index([1, 2, 3], dtype="int64")
508+
509+
For checking the data type of an index object, you can replace ``isinstance``
510+
checks with checking the ``dtype``:
511+
512+
.. code-block:: python
513+
514+
# replace
515+
isinstance(idx, pd.Int64Index)
516+
# with
517+
idx.dtype == "int64"
546518
547519
Currently, in order to maintain backward compatibility, calls to
548520
:class:`Index` will continue to return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`
549-
when given numeric data, but in the future, a :class:`NumericIndex` will be returned.
521+
when given numeric data, but in the future, an :class:`Index` will be returned.
550522

551523
*Current behavior*:
552524

@@ -562,9 +534,9 @@ when given numeric data, but in the future, a :class:`NumericIndex` will be retu
562534
.. code-block:: ipython
563535
564536
In [3]: pd.Index([1, 2, 3], dtype="int32")
565-
Out [3]: NumericIndex([1, 2, 3], dtype='int32')
537+
Out [3]: Index([1, 2, 3], dtype='int32')
566538
In [4]: pd.Index([1, 2, 3], dtype="uint64")
567-
Out [4]: NumericIndex([1, 2, 3], dtype='uint64')
539+
Out [4]: Index([1, 2, 3], dtype='uint64')
568540
569541
570542
.. _whatsnew_140.deprecations.frame_series_append:

pandas/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
Index,
7474
CategoricalIndex,
7575
RangeIndex,
76-
NumericIndex,
7776
MultiIndex,
7877
IntervalIndex,
7978
TimedeltaIndex,
@@ -199,7 +198,7 @@ def __getattr__(name):
199198
warnings.warn(
200199
f"pandas.{name} is deprecated "
201200
"and will be removed from pandas in a future version. "
202-
"Use pandas.NumericIndex with the appropriate dtype instead.",
201+
"Use pandas.Index with the appropriate dtype instead.",
203202
FutureWarning,
204203
stacklevel=2,
205204
)
@@ -335,7 +334,6 @@ def __getattr__(name):
335334
"NA",
336335
"NaT",
337336
"NamedAgg",
338-
"NumericIndex",
339337
"Period",
340338
"PeriodDtype",
341339
"PeriodIndex",

pandas/_testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
Index,
4545
IntervalIndex,
4646
MultiIndex,
47-
NumericIndex,
4847
RangeIndex,
4948
Series,
5049
bdate_range,
@@ -107,6 +106,7 @@
107106
from pandas.core.api import (
108107
Float64Index,
109108
Int64Index,
109+
NumericIndex,
110110
UInt64Index,
111111
)
112112
from pandas.core.arrays import (

pandas/core/indexes/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def _is_dtype_compat(self, other) -> Categorical:
291291

292292
@doc(Index.astype)
293293
def astype(self, dtype: Dtype, copy: bool = True) -> Index:
294-
from pandas import NumericIndex
294+
from pandas.core.api import NumericIndex
295295

296296
dtype = pandas_dtype(dtype)
297297

pandas/core/indexes/numeric.py

-7
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ class NumericIndex(Index):
8282
An NumericIndex instance can **only** contain numpy int64/32/16/8, uint64/32/16/8 or
8383
float64/32/16 dtype. In particular, ``NumericIndex`` *can not* hold Pandas numeric
8484
dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
85-
86-
Examples
87-
--------
88-
>>> pd.NumericIndex([1, 2, 3], dtype="int8")
89-
NumericIndex([1, 2, 3], dtype='int8')
90-
>>> pd.NumericIndex([1, 2, 3], dtype="float32")
91-
NumericIndex([1.0, 2.0, 3.0], dtype='float32')
9285
"""
9386

9487
_typ = "numericindex"

pandas/tests/api/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class TestPDApi(Base):
6565
"Index",
6666
"Int64Index",
6767
"MultiIndex",
68-
"NumericIndex",
6968
"Period",
7069
"PeriodIndex",
7170
"RangeIndex",

pandas/tests/base/test_unique.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from pandas.core.dtypes.common import is_datetime64tz_dtype
55

66
import pandas as pd
7-
from pandas import NumericIndex
87
import pandas._testing as tm
8+
from pandas.core.api import NumericIndex
99
from pandas.tests.base.common import allow_na_ops
1010

1111

pandas/tests/indexes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
Index,
2222
IntervalIndex,
2323
MultiIndex,
24-
NumericIndex,
2524
PeriodIndex,
2625
RangeIndex,
2726
Series,
@@ -32,6 +31,7 @@
3231
from pandas.core.api import ( # noqa:F401
3332
Float64Index,
3433
Int64Index,
34+
NumericIndex,
3535
UInt64Index,
3636
)
3737
from pandas.core.arrays import BaseMaskedArray

pandas/tests/indexes/multi/test_names.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test_setting_names_from_levels_raises():
148148
new.index.name = "bar"
149149

150150
assert pd.Index._no_setting_name is False
151-
assert pd.NumericIndex._no_setting_name is False
151+
assert pd.core.api.NumericIndex._no_setting_name is False
152152
assert pd.RangeIndex._no_setting_name is False
153153

154154

pandas/tests/indexes/numeric/test_numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import pandas as pd
77
from pandas import (
88
Index,
9-
NumericIndex,
109
Series,
1110
)
1211
import pandas._testing as tm
1312
from pandas.core.indexes.api import (
1413
Float64Index,
1514
Int64Index,
15+
NumericIndex,
1616
UInt64Index,
1717
)
1818
from pandas.tests.indexes.common import NumericBase

pandas/tests/indexes/test_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
DataFrame,
1717
DatetimeIndex,
1818
IntervalIndex,
19-
NumericIndex,
2019
PeriodIndex,
2120
RangeIndex,
2221
Series,
@@ -28,6 +27,7 @@
2827
from pandas.core.api import (
2928
Float64Index,
3029
Int64Index,
30+
NumericIndex,
3131
UInt64Index,
3232
)
3333
from pandas.core.indexes.api import (

pandas/tests/indexes/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
CategoricalIndex,
2121
DatetimeIndex,
2222
MultiIndex,
23-
NumericIndex,
2423
PeriodIndex,
2524
RangeIndex,
2625
TimedeltaIndex,
2726
)
2827
import pandas._testing as tm
28+
from pandas.core.api import NumericIndex
2929

3030

3131
class TestCommon:

pandas/tests/indexes/test_numpy_compat.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
CategoricalIndex,
66
DatetimeIndex,
77
Index,
8-
NumericIndex,
98
PeriodIndex,
109
TimedeltaIndex,
1110
isna,
1211
)
1312
import pandas._testing as tm
14-
from pandas.core.api import Float64Index
13+
from pandas.core.api import (
14+
Float64Index,
15+
NumericIndex,
16+
)
1517
from pandas.core.arrays import BooleanArray
1618
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
1719

0 commit comments

Comments
 (0)