10000 DEPR: Int64Index, UInt64Index & Float64Index by topper-123 · Pull Request #43028 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DEPR: Int64Index, UInt64Index & Float64Index #43028

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 16 commits into from
Sep 1, 2021
Prev Previous commit
Next Next commit
remove version numbers
  • Loading branch information
topper-123 committed Sep 1, 2021
commit e84b3634e5d5feff78c2d0698bf5f523377666dc
16 changes: 8 additions & 8 deletions doc/source/user_guide/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,9 @@ Int64Index and RangeIndex
.. deprecated:: 1.4.0
In pandas 2.0, :class:`NumericIndex` will become the default index type for numeric types
instead of ``Int64Index``, ``Float64Index`` and ``UInt64Index`` and those index types
are therefore deprecated and will be removed in Pandas 2.0.
are therefore deprecated and will be removed in a futire version.
See :ref:`here <advanced.numericindex>` for more.
``RangeIndex`` however, will not be removed, as it represents an optimized version of an integer index.
``RangeIndex`` will not be removed, as it represents an optimized version of an integer index.

:class:`Int64Index` is a fundamental basic index in pandas. This is an immutable array
implementing an ordered, sliceable set.
Expand All @@ -870,11 +870,11 @@ Float64Index
~~~~~~~~~~~~

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

By default a :class:`Float64Index` will be automatically created when passing floating, or mixed-integer-floating values in index creation.
This enables a pure label-based slicing paradigm that makes ``[],ix,loc`` for scalar indexing and slicing work exactly the
Expand Down Expand Up @@ -982,8 +982,8 @@ NumericIndex

In pandas 2.0, :class:`NumericIndex` will become the default index type for numeric types
instead of :class:`Int64Index`, :class:`Float64Index` and :class:`UInt64Index` and those index types
are therefore deprecated and will be removed in Pandas 2.0.
:class:`RangeIndex` however, will not be removed, as it represents an optimized version of an integer index.
are therefore deprecated and will be removed in a futureversion.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future version

:class:`RangeIndex` will not be removed as it represents an optimized version of an integer index.

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

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

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

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

Expand Down
20 changes: 10 additions & 10 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ It is now possible to create an index of any numpy int/uint/float dtype using th
pd.NumericIndex([1, 2, 3], dtype="uint32")
pd.NumericIndex([1, 2, 3], dtype="float32")

In order to maintain backwards compatibility, calls to the base :class:`Index` will in
pandas 1.x. return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`, where relevant.
In order to maintain backwards compatibility, calls to the base :class:`Index` will currently
return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`, where relevant.
For example, the code below returns an ``Int64Index`` with dtype ``int64``:

.. code-block:: ipython

In [1]: pd.Index([1, 2, 3], dtype="int8")
Int64Index([1, 2, 3], dtype='int64')

but will in Pandas 2.0 return a :class:`NumericIndex` with dtype ``int8``.
but will in a future version return a :class:`NumericIndex` with dtype ``int8``.

More generally, for the duration of Pandas 1.x, all operations that until now have
More generally, currently, all operations that until now have
returned :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index` will
continue to so. This means, that in order to use ``NumericIndex`` in Pandas 1.x, you
continue to so. This means, that in order to use ``NumericIndex`` in the current version, you
will have to call ``NumericIndex`` explicitly. For example the below series will have an ``Int64Index``:

.. code-block:: ipython
Expand All @@ -51,17 +51,17 @@ will have to call ``NumericIndex`` explicitly. For example the below series will
In [3]: ser.index
Int64Index([1, 2, 3], dtype='int64')

Instead, if you want to use a ``NumericIndex`` in Pandas 1.x, you should do:
Instead, if you want to use a ``NumericIndex``, you should do:

.. ipython:: python

idx = pd.NumericIndex([1, 2, 3], dtype="int8")
ser = pd.Series([1, 2, 3], index=idx)
ser.index

In Pandas 2.0, :class:`NumericIndex` will become the default numeric index type and
In a future version of Pandas, :class:`NumericIndex` will become the default numeric index type and
``Int64Index``, ``UInt64Index`` and ``Float64Index`` are therefore deprecated and will
be removed in pandas 2.0, see :ref:`here <whatsnew_140.deprecations.int64_uint64_float64index>` for more.
be removed in the future, see :ref:`here <whatsnew_140.deprecations.int64_uint64_float64index>` for more.

See :ref:`here <advanced.numericindex>` for more about :class:`NumericIndex`.

Expand Down Expand Up @@ -234,9 +234,9 @@ Deprecated Int64Index, UInt64Index & Float64Index
:class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index` have been deprecated
in favor of the new :class:`NumericIndex` and will be removed in Pandas 2.0 (:issue:`43028`).

For the duration of Pandas 1.x, in order to maintain backward compatibility, calls to
Currently, in order to maintain backward compatibility, calls to
:class:`Index` will continue to return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`
when given numeric data, but in Pandas 2.0, a :class:`NumericIndex` will be returned.
when given numeric data, but in the future, a :class:`NumericIndex` will be returned.

*Current behavior*:

Expand Down
3 changes: 3 additions & 0 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@


def __dir__():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Contributor Author
@topper-123 topper-123 Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so Int64Index etc. show up in dir calls.

Int64Index etc. have been quite prominent parts of the public API, so I think it's better that they still show up for the duration of Pandas 1.x. This should be removed in Pandas 2.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok can you add a comment to this effect

# GH43028
# Int64Index etc. are deprecated, but we still want them to be available in the dir.
# Remove in Pandas 2.0, when we remove Int64Index etc. from the code base.
return list(globals().keys()) + __deprecated_num_index_names


Expand Down
0