Skip to content

Commit e665083

Browse files
committed
DEPR: Int64Index, UInt64Index & Float64Index
1 parent b57ec1a commit e665083

File tree

4 files changed

+80
-49
lines changed

4 files changed

+80
-49
lines changed

doc/source/user_guide/advanced.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,11 @@ 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.
857+
are therefore deprecated and will be removed in Pandas 2.0.
858+
See :ref:`here <advanced.numericindex>` for more.
859859
``RangeIndex`` however, 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
@@ -869,11 +869,11 @@ implementing an ordered, sliceable set.
869869
Float64Index
870870
~~~~~~~~~~~~
871871

872-
.. note::
873-
872+
.. deprecated:: 1.4.0
874873
In pandas 2.0, :class:`NumericIndex` will become the default index type for numeric types
875874
instead of ``Int64Index``, ``Float64Index`` and ``UInt64Index`` and those index types
876-
will be removed. See :ref:`here <advanced.numericindex>` for more.
875+
are therefore deprecated and will be removed in Pandas 2.0.
876+
See :ref:`here <advanced.numericindex>` for more.
877877
``RangeIndex`` however, 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.
@@ -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 Pandas 2.0.
986+
:class:`RangeIndex` however, 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

doc/source/whatsnew/v1.4.0.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,18 @@ For example, the code below returns an ``Int64Index`` with dtype ``int64``:
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+
More generally, for the duration of Pandas 1.x, all operations that until now have
42+
returned :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index` will
43+
continue to so. This means, that in order to use ``NumericIndex``, you will have to call
44+
``NumericIndex`` explicitly. For example the below series will have an ``Int64Index``:
4645

4746
.. code-block:: ipython
4847
4948
In [2]: ser = pd.Series([1, 2, 3], index=[1, 2, 3])
5049
In [3]: ser.index
5150
Int64Index([1, 2, 3], dtype='int64')
5251
53-
Instead if you want to use a ``NumericIndex``, you should do:
52+
Instead, if you want to use a ``NumericIndex`` in Pandas 1.x, you should do:
5453

5554
.. ipython:: python
5655
@@ -59,7 +58,8 @@ Instead if you want to use a ``NumericIndex``, you should do:
5958
ser.index
6059
6160
In Pandas 2.0, :class:`NumericIndex` will become the default numeric index type and
62-
``Int64Index``, ``UInt64Index`` and ``Float64Index`` will be removed.
61+
``Int64Index``, ``UInt64Index`` and ``Float64Index`` are therefore deprecated and will
62+
be removed in pandas 2.0.
6363

6464
See :ref:`here <advanced.numericindex>` for more.
6565

@@ -199,6 +199,9 @@ Other API changes
199199

200200
Deprecations
201201
~~~~~~~~~~~~
202+
- Deprecated :class:`Int64Index` (:issue:`xxxxx`).
203+
- Deprecated :class:`UInt64Index` (:issue:`xxxxx`).
204+
- Deprecated :class:`Float64Index` (:issue:`xxxxx`).
202205
- Deprecated :meth:`Index.is_type_compatible` (:issue:`42113`)
203206
- Deprecated ``method`` argument in :meth:`Index.get_loc`, use ``index.get_indexer([label], method=...)`` instead (:issue:`42269`)
204207
- 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/core/indexes/base.py

Lines changed: 4 additions & 3 deletions
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
-----

pandas/core/indexes/numeric.py

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,51 +42,44 @@
4242
maybe_extract_name,
4343
)
4444

45-
_num_index_shared_docs = {}
46-
4745

48-
_num_index_shared_docs[
49-
"class_descr"
50-
] = """
46+
class NumericIndex(Index):
47+
"""
5148
Immutable sequence used for indexing and alignment. The basic object
52-
storing axis labels for all pandas objects. %(klass)s is a special case
53-
of `Index` with purely %(ltype)s labels. %(extra)s.
49+
storing axis labels for all pandas objects. NumericIndex is a special case
50+
of `Index` with purely numpy int/uint/float labels.
51+
52+
.. versionadded:: 1.4.0
53+
54+
Notes
55+
-----
56+
An NumericIndex instance can **only** contain numpy int64/32/16/8, uint64/32/16/8 or
57+
float64/32/16 dtype. In Particulat, ``NumericIndex`` *can not* hold Pandas numeric
58+
dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
5459
5560
Parameters
5661
----------
5762
data : array-like (1-dimensional)
58-
dtype : NumPy dtype (default: %(dtype)s)
63+
dtype : NumPy dtype (default: None)
5964
copy : bool
6065
Make a copy of input ndarray.
6166
name : object
6267
Name to be stored in the index.
6368
64-
Attributes
65-
----------
66-
None
67-
68-
Methods
69-
-------
70-
None
71-
7269
See Also
7370
--------
7471
Index : The base pandas Index type.
72+
Int64Index : Index of purely int64 labels (deprecated).
73+
UInt64Index : Index of purely uint64 labels (deprecated).
74+
Float64Index : Index of purely float64 labels (deprecated).
7575
76-
Notes
77-
-----
78-
An Index instance can **only** contain hashable objects.
79-
"""
80-
81-
82-
class NumericIndex(Index):
83-
_index_descr_args = {
84-
"klass": "NumericIndex",
85-
"ltype": "integer or float",
86-
"dtype": "inferred",
87-
"extra": "",
88-
}
89-
__doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args
76+
Examples
77+
--------
78+
>>> pd.NumericIndex([1, 2, 3])
79+
NumericIndex([1, 2, 3], dtype='int32')
80+
>>> pd.NumericIndex([1, 2, 3], dtype="int8")
81+
NumericIndex([1, 2, 3], dtype='int8')
82+
"""
9083

9184
_typ = "numericindex"
9285
_values: np.ndarray
@@ -360,6 +353,40 @@ def _format_native_types(
360353
)
361354

362355

356+
_num_index_shared_docs = {}
357+
358+
359+
_num_index_shared_docs[
360+
"class_descr"
361+
] = """
362+
Immutable sequence used for indexing and alignment. The basic object
363+
storing axis labels for all pandas objects. %(klass)s is a special case
364+
of `Index` with purely %(ltype)s labels. %(extra)s.
365+
366+
.. deprecated:: 1.4.0
367+
In pandas v2.0 %(klass)s will be removed and :class:`NumericIndex` used instead.
368+
%(klass)s will remain fully functional for the duration of pandas 1.x.
369+
370+
Parameters
371+
----------
372+
data : array-like (1-dimensional)
373+
dtype : NumPy dtype (default: %(dtype)s)
374+
copy : bool
375+
Make a copy of input ndarray.
376+
name : object
377+
Name to be stored in the index.
378+
379+
See Also
380+
--------
381+
Index : The base pandas Index type.
382+
NumericIndex : Index of numpy int/uint/float data.
383+
384+
Notes
385+
-----
386+
An Index instance can **only** contain hashable objects.
387+
"""
388+
389+
363390
class IntegerIndex(NumericIndex):
364391
"""
365392
This is an abstract class for Int64Index, UInt64Index.

0 commit comments

Comments
 (0)