-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1739,28 +1739,16 @@ def argsort(self, *args, **kwargs): | |
return result.argsort(*args, **kwargs) | ||
|
||
def __add__(self, other): | ||
if is_list_like(other): | ||
warnings.warn("using '+' to provide set union with Indexes is " | ||
"deprecated, use '|' or .union()", FutureWarning, | ||
stacklevel=2) | ||
if isinstance(other, Index): | ||
return self.union(other) | ||
return Index(np.array(self) + other) | ||
|
||
def __radd__(self, other): | ||
if is_list_like(other): | ||
warnings.warn("using '+' to provide set union with Indexes is " | ||
"deprecated, use '|' or .union()", FutureWarning, | ||
stacklevel=2) | ||
return Index(other + np.array(self)) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to remain I think? (the isinstance part) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this really should use _ensure_index I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But scalars should also work?
BTW, on numeric indexes, using lists is not allowed:
while on base Index it is currently allowed:
Unifying that would also be nice. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we are expanding the api w/o any testing of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for MultiIndex/Categorical nothing should be changed. I just renamed the method to disable add/sub for those, as there are no longer set ops. For
So by removing the But, as I said, I agree we should be more careful / do more careful testing (eg Int64Index does not allow to add with lists, base Index does). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be a break in here (e.g. where it currently calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand this comment. We had indeed tests that tested the union behaviour of |
||
__iadd__ = __add__ | ||
|
||
def __sub__(self, other): | ||
warnings.warn("using '-' to provide set differences with Indexes is " | ||
"deprecated, use .difference()", FutureWarning, | ||
stacklevel=2) | ||
return self.difference(other) | ||
raise TypeError("cannot perform __sub__ with this index type: " | ||
"{typ}".format(typ=type(self))) | ||
|
||
def __and__(self, other): | ||
return self.intersection(other) | ||
|
@@ -1990,7 +1978,8 @@ def symmetric_difference(self, other, result_name=None): | |
----- | ||
``symmetric_difference`` contains elements that appear in either | ||
``idx1`` or ``idx2`` but not both. Equivalent to the Index created by | ||
``(idx1 - idx2) + (idx2 - idx1)`` with duplicates dropped. | ||
``idx1.difference(idx2) | idx2.difference(idx1)`` with duplicates | ||
dropped. | ||
|
||
Examples | ||
-------- | ||
|
@@ -3333,8 +3322,8 @@ def _evaluate_compare(self, other): | |
cls.__ge__ = _make_compare(operator.ge) | ||
|
||
@classmethod | ||
def _add_numericlike_set_methods_disabled(cls): | ||
""" add in the numeric set-like methods to disable """ | ||
def _add_numeric_methods_add_sub_disabled(cls): | ||
""" add in the numeric add/sub methods to disable """ | ||
|
||
def _make_invalid_op(name): | ||
def invalid_op(self, other=None): | ||
|
@@ -3349,7 +3338,7 @@ def invalid_op(self, other=None): | |
|
||
@classmethod | ||
def _add_numeric_methods_disabled(cls): | ||
""" add in numeric methods to disable """ | ||
""" add in numeric methods to disable other than add/sub """ | ||
|
||
def _make_invalid_op(name): | ||
def invalid_op(self, other=None): | ||
|
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