Skip to content
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

DEPR: Int64Index, UInt64Index & Float64Index #43028

Merged
merged 16 commits into from
Sep 1, 2021

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Aug 13, 2021

Deprecates Int64Index, UInt64Index & Float64Index.

I don't think it will be sensible to emit a deprecation warning for these because they have a lot of internal usage as is, so I've just added texts explaining that these are deprecated and will be removed in Pandas 2.0.

EDIT: it does now emit an deprecation warning when accessed from the main namespace. See changes to pandas.__init__.py for implementation.

>>> pd.Int64Index
FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.NumericIndex with the appropriate dtype instead.

Notes
-----
An NumericIndex instance can **only** contain numpy int64/32/16/8, uint64/32/16/8 or
float64/32/16 dtype. In Particulat, ``NumericIndex`` *can not* hold Pandas numeric
Copy link
Member

Choose a reason for hiding this comment

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

Particulat -> particular

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@topper-123 topper-123 force-pushed the deprecate_old_numeric_indexes branch from fcf5cd6 to 5afecb2 Compare August 14, 2021 00:48
@jbrockmendel
Copy link
Member

xref #43002

@topper-123 topper-123 force-pushed the deprecate_old_numeric_indexes branch from 098f9b0 to ce2c306 Compare August 14, 2021 08:32
@lithomas1 lithomas1 added Deprecate Functionality to remove in pandas Index Related to the Index class or subclasses labels Aug 14, 2021
@lithomas1
Copy link
Member

lithomas1 commented Aug 14, 2021

IMHO, we probably should emit some sort of warning to users. I'm a little worried since 2.0 should be the next release after 1.4, and this is a somewhat big change. We can always suppress the deprecation warnings internally.

@topper-123
Copy link
Contributor Author

topper-123 commented Aug 17, 2021

I've made a new version where accessing Int64Index etc. in the main namespace emits a FutureWarning. So these give warnings now:

>>> import pandas as pd
>>> idx = pd.Int64Index([8, 9])
FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.NumericIndex with the appropriate dtype instead.
>>> isinstance(idx, pd.Int64Index)
FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.NumericIndex with the appropriate dtype instead.
True

but this does not:

>>> idx = pd.Index([8, 9])
>>> idx
Int64Index([8, 9], dtype='int64')
>>> isinstance(idx, pd.NumericIndex)
True

This last example doesn’t give warnings, because this access pattern is not deprecated, but will only change meaning in Pandas 2.0 (will return a NumericIndex rather than a Int64Index, + Int64Index is a subclass of NumericIndex).

These warnings should IMO give users a good hint on where they need to update their code to stay compatible in Pandas 2.0.

@topper-123
Copy link
Contributor Author

Got some failures still, but will work on them. The idea is completed, so commentd welcome.

@topper-123 topper-123 force-pushed the deprecate_old_numeric_indexes branch from d5a0689 to 33bb44f Compare August 19, 2021 07:46
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
will be removed. See :ref:`here <advanced.numericindex>` for more.
are therefore deprecated and will 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.

instead of saying Pandas 2.0, just a future version (we don't explicitly list the removal versions anywhere else i believe)

Copy link
Contributor

Choose a reason for hiding this comment

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

same comment applies to all docs below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done.

Copy link
Contributor

Choose a reason for hiding this comment

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

did you push the update?

__deprecated_num_index_names = ["Float64Index", "Int64Index", "UInt64Index"]


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

@topper-123
Copy link
Contributor Author

Updated.

@topper-123
Copy link
Contributor Author

Gentle ping…

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

very small comment, pls rebase

doc/source/user_guide/advanced.rst Show resolved Hide resolved
will be removed.
``RangeIndex`` however, will not be removed, as it represents an optimized version of an integer index.
instead of :class:`Int64Index`, :class:`Float64Index` and :class:`UInt64Index` and those index types
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

@jreback jreback merged commit 4fd0afa into pandas-dev:master Sep 1, 2021
@jreback
Copy link
Contributor

jreback commented Sep 1, 2021

thanks @topper-123 very nice!

@jbrockmendel
Copy link
Member

@topper-123 want to enforce this deprecation and rip out some code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants