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: deprecate Index.__getitem__ with float key #34193

Merged

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche commented May 15, 2020

See #34191 for motivation

Closes #34191

@jorisvandenbossche jorisvandenbossche added Deprecate Functionality to remove in pandas Index Related to the Index class or subclasses labels May 15, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1 milestone May 15, 2020
@jreback
Copy link
Contributor

jreback commented May 17, 2020

looks good, does this close #34191?

can you add a linkin the deprecations removal issue (2.0)

@@ -1188,6 +1189,8 @@ def _post_plot_logic(self, ax, data):
from matplotlib.ticker import FixedLocator

def get_label(i):
if is_float(i) and i.is_integer():
i = int(i)
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not really sure this is correct, but it's what is currently actually is being done (the conversion to int is just happening inside the Index.__getitem__). So this change is needed to preserve the current behaviour.

It's a bit strange that those xticks are floats, though. But maybe that's just a matplotlib behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is really strange ,what is i here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It are the values from ax.get_xticks(), see 5 lines below. I suppose matplotlib just always returns floats

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, just checked, matplotlib simply always returns floats. And it's only for the "integer floats" that we have a value in the index to put as xtick label.

@@ -586,6 +586,9 @@ Deprecations
- :func:`pandas.api.types.is_categorical` is deprecated and will be removed in a future version; use `:func:pandas.api.types.is_categorical_dtype` instead (:issue:`33385`)
- :meth:`Index.get_value` is deprecated and will be removed in a future version (:issue:`19728`)
- :meth:`DateOffset.__call__` is deprecated and will be removed in a future version, use ``offset + other`` instead (:issue:`34171`)
- Indexing an :class:`Index` object with a float key is deprecated, and will
raise an IndexError in the future. You can manually convert to an integer key
instead (:issue:`34191`).
Copy link
Member

Choose a reason for hiding this comment

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

usually we dont have a trailing period. double ticks on IndexError?

"""
To avoid numpy DeprecationWarnings, cast float to integer where valid.

Parameters
----------
val : scalar
warn_float : bool, default False
If True, raise deprecation warning for a float indexer.
Copy link
Member

Choose a reason for hiding this comment

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

"raise" -> "issue"


@pytest.mark.parametrize(
"idx", [Index([1, 2, 3]), Index([0.1, 0.2, 0.3]), Index(["a", "b", "c"])]
)
Copy link
Member

Choose a reason for hiding this comment

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

could use indices fixture?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, as the deprecation is only for those 3 index types

@jbrockmendel
Copy link
Member

few comments, generally looks good

@jorisvandenbossche
Copy link
Member Author

can you add a linkin the deprecations removal issue (2.0)

Added

@jorisvandenbossche jorisvandenbossche merged commit cb35d8a into pandas-dev:master May 23, 2020
@jorisvandenbossche jorisvandenbossche deleted the index-getitem-float branch May 23, 2020 13:17
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.

DEPR: deprecate Index.__getitem__ with float key
3 participants