-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: consistent signatures for equals methods #35636
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
""" | ||
Determines if two IntervalIndex objects contain the same elements. | ||
""" | ||
if self.is_(other): | ||
return True | ||
|
||
# if we can coerce to an II | ||
# then we can compare | ||
# if we can coerce to an IntervalIndex then we can compare |
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.
from #33940
Index and Series are consistent when it comes to not being equal with other array-likes:
not necessarily in this PR, but is this behaviour consistent with other Index types
>>> x = np.linspace(0, 100, num=3)
>>> x
array([ 0., 50., 100.])
>>>
>>> idx = pd.IntervalIndex.from_breaks(x)
>>> idx
IntervalIndex([(0.0, 50.0], (50.0, 100.0]],
closed='right',
dtype='interval[float64]')
>>>
>>> arr = idx.values
>>> arr
<IntervalArray>
[(0.0, 50.0], (50.0, 100.0]]
Length: 2, closed: right, dtype: interval[float64]
>>>
>>> idx.equals(arr)
True
>>>
>>> arr.equals(idx)
False
>>>
pandas/core/arrays/base.py
Outdated
@@ -762,7 +762,8 @@ def equals(self, other: "ExtensionArray") -> bool: | |||
""" | |||
if not type(self) == type(other): | |||
return False | |||
elif not self.dtype == other.dtype: | |||
other = cast(ExtensionArray, other) | |||
if not self.dtype == other.dtype: |
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 guess this is fine, though more consisten to use is_dtype_equal no?
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 had to break the if elif to get the cast in. so this is unchanged. but agreed is_dtype_equal
would be more consistent so will update.
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.
couple of places where codecov thinks we don't have tests, in a followup can remove / test if possible..
the code added was from static analysis. (mypy is still testing but codecov thinks we don't have tests) so in this case we don't want to remove. dynamic type testing has become less necessary now we are using mypy. |
No description provided.