-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: numericlike set ops on unsupported Indexes #10042
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
Conversation
return self.difference(other) | ||
__rsub__ = __sub__ |
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.
This isn't right -- this makes other - index
equal to index.difference(other)
, when it really should be other.difference(index)
. Maybe __rsub__
should just always raise TypeError
? Or I guess it could do _ensure_index(other).difference(index)
.
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.
oh, I just added __rsub__
for compat, i'll take it out (yes they should prob just always raise though)
warnings.warn("using '+' to provide set union with Indexes is deprecated, " | ||
"use '|' or .union()",FutureWarning) | ||
if isinstance(other, Index): |
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.
this is not correct I think, as now a list will show the warning, but not perform a set (union) operation (as a list is not an index)?
Should it not be like:
if com.is_list_like(other):
warnings.warn(...)
return self.union(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.
fixed
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.
@jreback I don't really see how this is fixed? It is still
if com.is_list_like(other):
warnings.warn(...)
if isinstance(other, Index):
return self.union(other)
So a list will trigger the warning, but not do the union set operation.
…dexes and lists (for +/-) (GH10038)
BUG: numericlike set ops on unsupported Indexes
There is also an inconsistency between the behaviour of
while
Shouldn't this last one also not do the list_like check (so you don't do a set operation when subtracting a scalar)? I can do a PR if this seems OK |
I guess technically the warning is showing up when using This is concatenation, and IS convenient
If you want to change |
yes, that one as well.
So for the list, it displays both a warning and an error, and those two contradict each other (and I think it is also more logical to have the same behaviour as with an Index) |
@jorisvandenbossche ahh, ok, I see. I think the example I used broadcast correctly, so yes this needs cleaning up. be my guest! |
closes #10038
closes #10039
CategoricalIndex
now raiseTypeError
on ops like :idx - idx
(we are moving all non-numeric Indexes to this, but just deprecated for now on existing index types)idx - ['a','b']
)