-
-
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
Raise a ValueError when index and data lengths don't match #26911
Conversation
Codecov Report
@@ Coverage Diff @@
## master #26911 +/- ##
==========================================
- Coverage 91.87% 91.86% -0.01%
==========================================
Files 180 180
Lines 50712 50714 +2
==========================================
- Hits 46590 46588 -2
- Misses 4122 4126 +4
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26911 +/- ##
==========================================
- Coverage 92% 91.99% -0.01%
==========================================
Files 180 180
Lines 50754 50755 +1
==========================================
- Hits 46698 46694 -4
- Misses 4056 4061 +5
Continue to review full report at Codecov.
|
pandas/tests/indexing/test_loc.py
Outdated
@@ -196,6 +196,19 @@ def test_loc_getitem_bool(self): | |||
self.check_result('bool', 'loc', b, 'ix', b, typs=['empty'], | |||
fails=KeyError) | |||
|
|||
def test_loc_getitem_bool_diff_len(self): |
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.
same comment as above
Which exception type would you prefer: ValueError, IndexError, IndexingError? |
I tried Sequence and Union[Series, Sequence], didn't work |
@@ -665,6 +665,7 @@ Indexing | |||
^^^^^^^^ | |||
|
|||
- Improved exception message when calling :meth:`DataFrame.iloc` with a list of non-numeric objects (:issue:`25753`). | |||
- Improved exception message when calling ``.iloc`` or ``.loc`` with a boolean indexer with different length (:issue:`26658`). |
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 quite accurate, since previously there may not have even been an exception, right?
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.
Hmm, maybe I misunderstood what @jreback said above. I thought he was referencing the fact that an exception was already getting raised if there are too many true values (that's the example you provided in the description). Now it's just getting raised whenever the lengths are different.
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.
#26658 was initially about too few indexers not raising
In [1]: import pandas as pd
s =
In [2]: s = pd.Series([1, 2, 3])
In [3]: s.iloc[[True, False]]
Out[3]:
0 1
dtype: int64
I think this is all good, aside from the release note. |
Thanks @krsnik93! |
git diff upstream/master -u -- "*.py" | flake8 --diff