API/DEPR: Remove +/- as setops for Index (GH8227) by jorisvandenbossche · Pull Request #14127 · pandas-dev/pandas (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@jorisvandenbossche

xref #13777, deprecations put in place in #8227

jreback

Choose a reason for hiding this comment

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

I think this is not defined in super? so this should raise NotImplementedError I think?

Choose a reason for hiding this comment

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

yep, this is something that I still have to handle.

The problem is that sub/add are added for subclasses in either _add_numericlike_set_methods_disabled or _add_numeric_methods or both ovenwritten (always handled both), but in the base class we only want __add__ and not __sub__

If I leave it in here, I think it should rather raise a TypeError? (for usage of base Index class)

Choose a reason for hiding this comment

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

yeah TypeError is prob ok too

the only reason to raise NotImplemmeted is that then subclasses could override - but we don't want that

@codecov-io

Current coverage is 85.25% (diff: 100%)

Merging #14127 into master will decrease coverage by <.01%

@@ master #14127 diff @@

Files 139 139
Lines 50501 50495 -6
Methods 0 0
Messages 0 0
Branches 0 0

Powered by Codecov. Last update 4488f18...dbcc655

@jreback

@jorisvandenbossche

@jreback yep, as it is quite a substantial change (for people that ignored the warnings)

Is there a reason that we do not allow numeric ops for the base Index class? (eg pd.Index(['a', 'b'] could have a clear meaning, just letting the objects determine whether an operation can be handled)

Because eg the __add__ in the Index class could benefit from the machinery in _add_numeric_methods_binary (eg to ensure attributes like name are passed correctly. Something that is also not correct on current master)

@jreback

I think we don't allow numeric operations on Index as only possible one is add for string concat
nothing else makes sense

in general these r not well defined so no reason to allow

@shoyer

I think we should let the objects in the Index decide whether the numeric operation is valid or not. This is the approach NumPy uses for object dtype. For example, one might put decimal objects in a pandas.Index.

@jreback

the numpy approach leads to lots of bugs and edge cases - constraining things somewhat to not allowing everything on everything is much more user friendly

decimal objects in an Index are a disaster - should not be encouraged

jreback

Choose a reason for hiding this comment

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

I would be more specific that 'when possible' (maybe say for numeric & datetimelike)

Choose a reason for hiding this comment

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

datetimelike not yet (DatetimeIndex - DatetimeIndex does still set op, but this one is a bit more work to remove).

And + also works for strings, so not only numeric. Further, for numeric indices, + and - did already do numeric ops and not setops .. (to make it a bit more complex :-))

So I did not directly come up with a more accurate but simple wording, but if you have a suggestion all ears!

@jorisvandenbossche jorisvandenbossche changed the title[WIP] API/DEPR: Remove +/- as setops for Index (GH8227) API/DEPR: Remove +/- as setops for Index (GH8227)

Sep 1, 2016

jreback

Choose a reason for hiding this comment

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

make this clear that this ONLY applies to Index itself and not-subclasses (maybe show that numeric/datetimelike ops are unchanged)

Choose a reason for hiding this comment

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

yes, will try to clarify

@jreback

@jorisvandenbossche

trbs added a commit to trbs/pandas that referenced this pull request

Sep 12, 2016

@trbs

…eter

trbs added a commit to trbs/pandas that referenced this pull request

Sep 12, 2016

@trbs

Labels