Skip to content

Commit 8842104

Browse files
topper-123feefladder
authored andcommitted
DEPR: Int64Index, UInt64Index & Float64Index (pandas-dev#43028)
1 parent 58fa02b commit 8842104

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+363
-185
lines changed

doc/source/user_guide/advanced.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -851,12 +851,12 @@ values **not** in the categories, similarly to how you can reindex **any** panda
851851
Int64Index and RangeIndex
852852
~~~~~~~~~~~~~~~~~~~~~~~~~
853853

854-
.. note::
855-
854+
.. deprecated:: 1.4.0
856855
In pandas 2.0, :class:`NumericIndex` will become the default index type for numeric types
857856
instead of ``Int64Index``, ``Float64Index`` and ``UInt64Index`` and those index types
858-
will be removed. See :ref:`here <advanced.numericindex>` for more.
859-
``RangeIndex`` however, will not be removed, as it represents an optimized version of an integer index.
857+
are therefore deprecated and will be removed in a futire version.
858+
See :ref:`here <advanced.numericindex>` for more.
859+
``RangeIndex`` will not be removed, as it represents an optimized version of an integer index.
860860

861861
:class:`Int64Index` is a fundamental basic index in pandas. This is an immutable array
862862
implementing an ordered, sliceable set.
@@ -869,12 +869,12 @@ implementing an ordered, sliceable set.
869869
Float64Index
870870
~~~~~~~~~~~~
871871

872-
.. note::
873-
874-
In pandas 2.0, :class:`NumericIndex` will become the default index type for numeric types
872+
.. deprecated:: 1.4.0
873+
:class:`NumericIndex` will become the default index type for numeric types in the future
875874
instead of ``Int64Index``, ``Float64Index`` and ``UInt64Index`` and those index types
876-
will be removed. See :ref:`here <advanced.numericindex>` for more.
877-
``RangeIndex`` however, will not be removed, as it represents an optimized version of an integer index.
875+
are therefore deprecated and will be removed in a future version of Pandas.
876+
See :ref:`here <advanced.numericindex>` for more.
877+
``RangeIndex`` will not be removed as it represents an optimized version of an integer index.
878878

879879
By default a :class:`Float64Index` will be automatically created when passing floating, or mixed-integer-floating values in index creation.
880880
This enables a pure label-based slicing paradigm that makes ``[],ix,loc`` for scalar indexing and slicing work exactly the
@@ -981,9 +981,9 @@ NumericIndex
981981
.. note::
982982

983983
In pandas 2.0, :class:`NumericIndex` will become the default index type for numeric types
984-
instead of ``Int64Index``, ``Float64Index`` and ``UInt64Index`` and those index types
985-
will be removed.
986-
``RangeIndex`` however, will not be removed, as it represents an optimized version of an integer index.
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.
987987

988988
:class:`NumericIndex` is an index type that can hold data of any numpy int/uint/float dtype. For example:
989989

@@ -998,7 +998,7 @@ NumericIndex
998998
``UInt64Index`` except that it can hold any numpy int, uint or float dtype.
999999

10001000
Until Pandas 2.0, you will have to call ``NumericIndex`` explicitly in order to use it, like in the example above.
1001-
In Pandas 2.0, ``NumericIndex`` will become the default pandas numeric index type and will automatically be used where appropriate.
1001+
In the future, ``NumericIndex`` will become the default pandas numeric index type and will automatically be used where appropriate.
10021002

10031003
Please notice that ``NumericIndex`` *can not* hold Pandas numeric dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
10041004

doc/source/whatsnew/v0.20.0.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,12 @@ or purely non-negative, integers. Previously, handling these integers would
248248
result in improper rounding or data-type casting, leading to incorrect results.
249249
Notably, a new numerical index, ``UInt64Index``, has been created (:issue:`14937`)
250250

251-
.. ipython:: python
251+
.. code-block:: ipython
252252
253-
idx = pd.UInt64Index([1, 2, 3])
254-
df = pd.DataFrame({'A': ['a', 'b', 'c']}, index=idx)
255-
df.index
253+
In [1]: idx = pd.UInt64Index([1, 2, 3])
254+
In [2]: df = pd.DataFrame({'A': ['a', 'b', 'c']}, index=idx)
255+
In [3]: df.index
256+
Out[3]: UInt64Index([1, 2, 3], dtype='uint64')
256257
257258
- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`, :issue:`14982`)
258259
- Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`)

doc/source/whatsnew/v0.23.0.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -861,21 +861,21 @@ Previous behavior:
861861
862862
Current behavior:
863863

864-
.. ipython:: python
864+
.. code-block:: ipython
865865
866-
index = pd.Int64Index([-1, 0, 1])
866+
In [12]: index = pd.Int64Index([-1, 0, 1])
867867
# division by zero gives -infinity where negative,
868868
# +infinity where positive, and NaN for 0 / 0
869-
index / 0
869+
In [13]: index / 0
870870
871871
# The result of division by zero should not depend on
872872
# whether the zero is int or float
873-
index / 0.0
873+
In [14]: index / 0.0
874874
875-
index = pd.UInt64Index([0, 1])
876-
index / np.array([0, 0], dtype=np.uint64)
875+
In [15]: index = pd.UInt64Index([0, 1])
876+
In [16]: index / np.array([0, 0], dtype=np.uint64)
877877
878-
pd.RangeIndex(1, 5) / 0
878+
In [17]: pd.RangeIndex(1, 5) / 0
879879
880880
.. _whatsnew_0230.api_breaking.extract:
881881

doc/source/whatsnew/v0.25.0.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,12 @@ considered commutative, such that ``A.union(B) == B.union(A)`` (:issue:`23525`).
473473
474474
*New behavior*:
475475

476-
.. ipython:: python
476+
.. code-block:: python
477477
478-
pd.period_range('19910905', periods=2).union(pd.Int64Index([1, 2, 3]))
479-
pd.Index([], dtype=object).union(pd.Index([1, 2, 3]))
478+
In [3]: pd.period_range('19910905', periods=2).union(pd.Int64Index([1, 2, 3]))
479+
Out[3]: Index([1991-09-05, 1991-09-06, 1, 2, 3], dtype='object')
480+
In [4]: pd.Index([], dtype=object).union(pd.Index([1, 2, 3]))
481+
Out[4]: Index([1, 2, 3], dtype='object')
480482
481483
Note that integer- and floating-dtype indexes are considered "compatible". The integer
482484
values are coerced to floating point, which may result in loss of precision. See

doc/source/whatsnew/v1.4.0.rst

+48-11
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,41 @@ It is now possible to create an index of any numpy int/uint/float dtype using th
2929
pd.NumericIndex([1, 2, 3], dtype="uint32")
3030
pd.NumericIndex([1, 2, 3], dtype="float32")
3131
32-
In order to maintain backwards compatibility, calls to the base :class:`Index` will in
33-
pandas 1.x. return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`.
32+
In order to maintain backwards compatibility, calls to the base :class:`Index` will currently
33+
return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`, where relevant.
3434
For example, the code below returns an ``Int64Index`` with dtype ``int64``:
3535

3636
.. code-block:: ipython
3737
3838
In [1]: pd.Index([1, 2, 3], dtype="int8")
3939
Int64Index([1, 2, 3], dtype='int64')
4040
41-
For the duration of Pandas 1.x, in order to maintain backwards compatibility, all
42-
operations that until now have returned :class:`Int64Index`, :class:`UInt64Index` and
43-
:class:`Float64Index` will continue to so. This means, that in order to use
44-
``NumericIndex``, you will have to call ``NumericIndex`` explicitly. For example the below series
45-
will have an ``Int64Index``:
41+
but will in a future version return a :class:`NumericIndex` with dtype ``int8``.
42+
43+
More generally, currently, all operations that until now have
44+
returned :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index` will
45+
continue to so. This means, that in order to use ``NumericIndex`` in the current version, you
46+
will have to call ``NumericIndex`` explicitly. For example the below series will have an ``Int64Index``:
4647

4748
.. code-block:: ipython
4849
4950
In [2]: ser = pd.Series([1, 2, 3], index=[1, 2, 3])
5051
In [3]: ser.index
5152
Int64Index([1, 2, 3], dtype='int64')
5253
53-
Instead if you want to use a ``NumericIndex``, you should do:
54+
Instead, if you want to use a ``NumericIndex``, you should do:
5455

5556
.. ipython:: python
5657
5758
idx = pd.NumericIndex([1, 2, 3], dtype="int8")
5859
ser = pd.Series([1, 2, 3], index=idx)
5960
ser.index
6061
61-
In Pandas 2.0, :class:`NumericIndex` will become the default numeric index type and
62-
``Int64Index``, ``UInt64Index`` and ``Float64Index`` will be removed.
62+
In a future version of Pandas, :class:`NumericIndex` will become the default numeric index type and
63+
``Int64Index``, ``UInt64Index`` and ``Float64Index`` are therefore deprecated and will
64+
be removed in the future, see :ref:`here <whatsnew_140.deprecations.int64_uint64_float64index>` for more.
6365

64-
See :ref:`here <advanced.numericindex>` for more.
66+
See :ref:`here <advanced.numericindex>` for more about :class:`NumericIndex`.
6567

6668
.. _whatsnew_140.enhancements.styler:
6769

@@ -224,6 +226,41 @@ Other API changes
224226

225227
Deprecations
226228
~~~~~~~~~~~~
229+
230+
.. _whatsnew_140.deprecations.int64_uint64_float64index:
231+
232+
Deprecated Int64Index, UInt64Index & Float64Index
233+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234+
:class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index` have been deprecated
235+
in favor of the new :class:`NumericIndex` and will be removed in Pandas 2.0 (:issue:`43028`).
236+
237+
Currently, in order to maintain backward compatibility, calls to
238+
:class:`Index` will continue to return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`
239+
when given numeric data, but in the future, a :class:`NumericIndex` will be returned.
240+
241+
*Current behavior*:
242+
243+
.. code-block:: ipython
244+
245+
In [1]: pd.Index([1, 2, 3], dtype="int32")
246+
Out [1]: Int64Index([1, 2, 3], dtype='int64')
247+
In [1]: pd.Index([1, 2, 3], dtype="uint64")
248+
Out [1]: UInt64Index([1, 2, 3], dtype='uint64')
249+
250+
*Future behavior*:
251+
252+
.. code-block:: ipython
253+
254+
In [3]: pd.Index([1, 2, 3], dtype="int32")
255+
Out [3]: NumericIndex([1, 2, 3], dtype='int32')
256+
In [4]: pd.Index([1, 2, 3], dtype="uint64")
257+
Out [4]: NumericIndex([1, 2, 3], dtype='uint64')
258+
259+
260+
.. _whatsnew_140.deprecations.other:
261+
262+
Other Deprecations
263+
^^^^^^^^^^^^^^^^^^
227264
- Deprecated :meth:`Index.is_type_compatible` (:issue:`42113`)
228265
- Deprecated ``method`` argument in :meth:`Index.get_loc`, use ``index.get_indexer([label], method=...)`` instead (:issue:`42269`)
229266
- Deprecated treating integer keys in :meth:`Series.__setitem__` as positional when the index is a :class:`Float64Index` not containing the key, a :class:`IntervalIndex` with no entries containing the key, or a :class:`MultiIndex` with leading :class:`Float64Index` level not containing the key (:issue:`33469`)

pandas/__init__.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@
7070
# indexes
7171
Index,
7272
CategoricalIndex,
73-
Int64Index,
74-
UInt64Index,
7573
RangeIndex,
76-
Float64Index,
7774
NumericIndex,
7875
MultiIndex,
7976
IntervalIndex,
@@ -186,10 +183,35 @@
186183

187184

188185
# GH 27101
186+
__deprecated_num_index_names = ["Float64Index", "Int64Index", "UInt64Index"]
187+
188+
189+
def __dir__():
190+
# GH43028
191+
# Int64Index etc. are deprecated, but we still want them to be available in the dir.
192+
# Remove in Pandas 2.0, when we remove Int64Index etc. from the code base.
193+
return list(globals().keys()) + __deprecated_num_index_names
194+
195+
189196
def __getattr__(name):
190197
import warnings
191198

192-
if name == "datetime":
199+
if name in __deprecated_num_index_names:
200+
warnings.warn(
201+
f"pandas.{name} is deprecated "
202+
"and will be removed from pandas in a future version. "
203+
"Use pandas.NumericIndex with the appropriate dtype instead.",
204+
FutureWarning,
205+
stacklevel=2,
206+
)
207+
from pandas.core.api import Float64Index, Int64Index, UInt64Index
208+
209+
return {
210+
"Float64Index": Float64Index,
211+
"Int64Index": Int64Index,
212+
"UInt64Index": UInt64Index,
213+
}[name]
214+
elif name == "datetime":
193215
warnings.warn(
194216
"The pandas.datetime class is deprecated "
195217
"and will be removed from pandas in a future version. "

pandas/_testing/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@
4545
CategoricalIndex,
4646
DataFrame,
4747
DatetimeIndex,
48-
Float64Index,
4948
Index,
50-
Int64Index,
5149
IntervalIndex,
5250
MultiIndex,
5351
NumericIndex,
5452
RangeIndex,
5553
Series,
56-
UInt64Index,
5754
bdate_range,
5855
)
5956
from pandas._testing._io import ( # noqa:F401
@@ -106,6 +103,11 @@
106103
use_numexpr,
107104
with_csv_dialect,
108105
)
106+
from pandas.core.api import (
107+
Float64Index,
108+
Int64Index,
109+
UInt64Index,
110+
)
109111
from pandas.core.arrays import (
110112
DatetimeArray,
111113
PandasArray,

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ def __init__(self, obj, n: int, keep: str, columns):
13341334

13351335
def compute(self, method: str) -> DataFrame:
13361336

1337-
from pandas import Int64Index
1337+
from pandas.core.api import Int64Index
13381338

13391339
n = self.n
13401340
frame = self.obj

pandas/core/indexes/base.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,10 @@ class Index(IndexOpsMixin, PandasObject):
276276
DatetimeIndex : Index of datetime64 data.
277277
TimedeltaIndex : Index of timedelta64 data.
278278
PeriodIndex : Index of Period data.
279-
Int64Index : A special case of :class:`Index` with purely integer labels.
280-
UInt64Index : A special case of :class:`Index` with purely unsigned integer labels.
281-
Float64Index : A special case of :class:`Index` with purely float labels.
279+
NumericIndex : Index of numpy int/uint/float data.
280+
Int64Index : Index of purely int64 labels (deprecated).
281+
UInt64Index : Index of purely uint64 labels (deprecated).
282+
Float64Index : Index of purely float64 labels (deprecated).
282283
283284
Notes
284285
-----
@@ -571,15 +572,15 @@ def _dtype_to_subclass(cls, dtype: DtypeObj):
571572
return TimedeltaIndex
572573

573574
elif is_float_dtype(dtype):
574-
from pandas import Float64Index
575+
from pandas.core.api import Float64Index
575576

576577
return Float64Index
577578
elif is_unsigned_integer_dtype(dtype):
578-
from pandas import UInt64Index
579+
from pandas.core.api import UInt64Index
579580

580581
return UInt64Index
581582
elif is_signed_integer_dtype(dtype):
582-
from pandas import Int64Index
583+
from pandas.core.api import Int64Index
583584

584585
return Int64Index
585586

0 commit comments

Comments
 (0)