-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
API/DEPR: Remove +/- as setops for Index (GH8227) #14127
API/DEPR: Remove +/- as setops for Index (GH8227) #14127
Conversation
return Index(other + np.array(self)) | ||
|
||
__iadd__ = __add__ | ||
|
||
def __sub__(self, other): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
bc44066
to
a7dfd73
Compare
Current coverage is 85.25% (diff: 100%)@@ master #14127 diff @@
==========================================
Files 139 139
Lines 50501 50495 -6
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 43058 43051 -7
- Misses 7443 7444 +1
Partials 0 0
|
a7dfd73
to
96b827d
Compare
@jorisvandenbossche we should do this for the RC as well. |
@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 Because eg the |
I think we don't allow numeric operations on Index as only possible one is add for string concat in general these r not well defined so no reason to allow |
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. |
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 |
Addition and subtraction of certain Index types performed set operations | ||
(set union and difference). This behaviour was already deprecated since 0.15.0, | ||
and is now disabled and, when possible, ``+`` | ||
and ``-`` are used for numeric operations (:issue:`8227`, :issue:`14127`). |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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!
In [1]: pd.Index(['a', 'b']) + pd.Index(['a', 'c']) | ||
FutureWarning: using '+' to provide set union with Indexes is deprecated, use '|' or .union() | ||
Out[1]: Index(['a', 'b', 'c'], dtype='object') | ||
|
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
@jorisvandenbossche some small comments, but otherwise lgtm. merge when ready. |
96b827d
to
dbcc655
Compare
…eter * github.com:pydata/pandas: (554 commits) BUG: compat with Stata ver 111 Fix: F999 dictionary key '2000q4' repeated with different values (pandas-dev#14198) BLD: Test for Python 3.5 with C locale BUG: DatetimeTZBlock can't assign values near dst boundary BUG: union_categorical with Series and cat idx BUG: fix str.contains for series containing only nan values BUG: Categorical constructor not idempotent with ext dtype TST: Make encoded sep check more locale sensitive (pandas-dev#14161) DOC: minor typo in 0.19.0 whatsnew file (pandas-dev#14185) BUG: fix tz-aware datetime convert to DatetimeIndex (GH 14088) BUG : bug in setting a slice of a Series with a np.timedelta64 RLS: v0.19.0rc1 DOC: clean-up 0.19.0 whatsnew file (pandas-dev#14176) DOC: cleanup build warnings (pandas-dev#14172) Add steps to run gbq integration testing to the contributing docs (pandas-dev#14144) ENH: concat and append now can handle unordered categories (pandas-dev#13767) DEPR: Deprecate pandas.core.datetools (pandas-dev#14105) API/DEPR: Remove +/- as setops for DatetimeIndex/PeriodIndex (GH9630) (pandas-dev#14164) Fix trivial typo in comment (pandas-dev#14174) API/DEPR: Remove +/- as setops for Index (GH8227) (pandas-dev#14127) ...
* github.com:pydata/pandas: (554 commits) BUG: compat with Stata ver 111 Fix: F999 dictionary key '2000q4' repeated with different values (pandas-dev#14198) BLD: Test for Python 3.5 with C locale BUG: DatetimeTZBlock can't assign values near dst boundary BUG: union_categorical with Series and cat idx BUG: fix str.contains for series containing only nan values BUG: Categorical constructor not idempotent with ext dtype TST: Make encoded sep check more locale sensitive (pandas-dev#14161) DOC: minor typo in 0.19.0 whatsnew file (pandas-dev#14185) BUG: fix tz-aware datetime convert to DatetimeIndex (GH 14088) BUG : bug in setting a slice of a Series with a np.timedelta64 RLS: v0.19.0rc1 DOC: clean-up 0.19.0 whatsnew file (pandas-dev#14176) DOC: cleanup build warnings (pandas-dev#14172) Add steps to run gbq integration testing to the contributing docs (pandas-dev#14144) ENH: concat and append now can handle unordered categories (pandas-dev#13767) DEPR: Deprecate pandas.core.datetools (pandas-dev#14105) API/DEPR: Remove +/- as setops for DatetimeIndex/PeriodIndex (GH9630) (pandas-dev#14164) Fix trivial typo in comment (pandas-dev#14174) API/DEPR: Remove +/- as setops for Index (GH8227) (pandas-dev#14127) ...
xref #13777, deprecations put in place in #8227
git diff upstream/master | flake8 --diff