-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
operator equal on Index should behavior similarly to Series #9947
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,76 @@ Backwards incompatible API changes | |
|
||
.. _whatsnew_0170.api_breaking: | ||
|
||
- Operator equal on Index should behavior similarly to Series (:issue:`9947`) | ||
|
||
Starting in v0.17.0, comparing ``Index`` objects of different lengths will raise | ||
a ``ValueError``. This is to be consistent with the behavior of ``Series``. | ||
|
||
Previous behavior: | ||
|
||
.. code-block:: python | ||
|
||
In [2]: pd.Index([1, 2, 3]) == pd.Index([1, 4, 5]) | ||
Out[2]: array([ True, False, False], dtype=bool) | ||
|
||
In [3]: pd.Index([1, 2, 3]) == pd.Index([2]) | ||
Out[3]: array([False, True, False], dtype=bool) | ||
|
||
In [4]: pd.Index([1, 2, 3]) == pd.Index([1, 2]) | ||
Out[4]: False | ||
|
||
In [5]: pd.Series([1, 2, 3]) == pd.Series([1, 4, 5]) | ||
Out[5]: | ||
0 True | ||
1 False | ||
2 False | ||
dtype: bool | ||
|
||
In [6]: pd.Series([1, 2, 3]) == pd.Series([2]) | ||
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. e.g. use this in the basics.rst |
||
ValueError: Series lengths must match to compare | ||
|
||
In [7]: pd.Series([1, 2, 3]) == pd.Series([1, 2]) | ||
ValueError: Series lengths must match to compare | ||
|
||
New behavior: | ||
|
||
.. code-block:: python | ||
|
||
In [8]: pd.Index([1, 2, 3]) == pd.Index([1, 4, 5]) | ||
Out[8]: array([ True, False, False], dtype=bool) | ||
|
||
In [9]: pd.Index([1, 2, 3]) == pd.Index([2]) | ||
ValueError: Lengths must match to compare | ||
|
||
In [10]: pd.Index([1, 2, 3]) == pd.Index([1, 2]) | ||
ValueError: Lengths must match to compare | ||
|
||
In [11]: pd.Series([1, 2, 3]) == pd.Series([1, 4, 5]) | ||
Out[11]: | ||
0 True | ||
1 False | ||
2 False | ||
dtype: bool | ||
|
||
In [12]: pd.Series([1, 2, 3]) == pd.Series([2]) | ||
ValueError: Series lengths must match to compare | ||
|
||
In [13]: pd.Series([1, 2, 3]) == pd.Series([1, 2]) | ||
ValueError: Series lengths must match to compare | ||
|
||
Note that this is different from the ``numpy`` behavior where a comparison can | ||
be broadcast: | ||
|
||
.. ipython:: python | ||
|
||
np.array([1, 2, 3]) == np.array([1]) | ||
|
||
or it can return False if broadcasting can not be done: | ||
|
||
.. ipython:: python | ||
|
||
np.array([1, 2, 3]) == np.array([1, 2]) | ||
|
||
.. _whatsnew_0170.api_breaking.other: | ||
|
||
Other API Changes | ||
|
@@ -149,3 +219,4 @@ Bug Fixes | |
|
||
- Bug in ``Series.plot(kind='hist')`` Y Label not informative (:issue:`10485`) | ||
|
||
- Bug in operator equal on Index not being consistent with Series (:issue:`9947`) |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you also add here the previous broadcasting behaviour which has changed?