Skip to content
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

Merged
merged 16 commits into from
Jun 26, 2019

Conversation

krsnik93
Copy link
Contributor

@krsnik93 krsnik93 commented Jun 17, 2019

@codecov
Copy link

codecov bot commented Jun 17, 2019

Codecov Report

Merging #26911 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.46% <100%> (ø) ⬆️
#single 41.09% <50%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexing.py 93.5% <100%> (+0.01%) ⬆️
pandas/io/gbq.py 88.88% <0%> (-11.12%) ⬇️
pandas/core/frame.py 96.88% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update baa77c3...14c7461. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 17, 2019

Codecov Report

Merging #26911 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.63% <100%> (-0.01%) ⬇️
#single 41.82% <57.14%> (-0.1%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexing.py 93.3% <100%> (-0.19%) ⬇️
pandas/io/gbq.py 88.88% <0%> (-11.12%) ⬇️
pandas/core/frame.py 96.89% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.94% <0%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4aa1d6...4f819c3. Read the comment docs.

@@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Error Reporting Incorrect or improved errors from pandas labels Jun 19, 2019
@krsnik93
Copy link
Contributor Author

Which exception type would you prefer: ValueError, IndexError, IndexingError?

@krsnik93
Copy link
Contributor Author

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`).
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

@TomAugspurger
Copy link
Contributor

I think this is all good, aside from the release note.

@TomAugspurger TomAugspurger merged commit d94146c into pandas-dev:master Jun 26, 2019
@TomAugspurger
Copy link
Contributor

Thanks @krsnik93!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

loc allows different length boolean indexer
3 participants