Skip to content

ERR: Raise a simpler backtrace for missing key #21558

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 2 commits into from
Jun 21, 2018

Conversation

toobaz
Copy link
Member

@toobaz toobaz commented Jun 20, 2018

@toobaz toobaz added Indexing Related to indexing on series/frames, not to indexes themselves Error Reporting Incorrect or improved errors from pandas labels Jun 20, 2018
@@ -1818,6 +1816,9 @@ def error():
except:
error()
Copy link
Contributor

Choose a reason for hiding this comment

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

In my last few commits this except clause hid the cause of the underlying exception. Cant it just be removed altogether and let exceptions raise as they occur onstead of goinc through error()?

Copy link
Member Author

Choose a reason for hiding this comment

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

In my last few commits this except clause hid the cause of the underlying exception.

Well, in principle this is its exact goal ;-) Can you provide an example? I guess we should just specify the exceptions it catches.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cant it just be removed altogether and let exceptions raise as they occur onstead of goinc through error()?

@topper-123 well, maybe you're right!

@codecov
Copy link

codecov bot commented Jun 20, 2018

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21558      +/-   ##
==========================================
- Coverage   91.92%   91.92%   -0.01%     
==========================================
  Files         153      153              
  Lines       49561    49561              
==========================================
- Hits        45559    45557       -2     
- Misses       4002     4004       +2
Flag Coverage Δ
#multiple 90.32% <100%> (-0.01%) ⬇️
#single 41.8% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexing.py 93.23% <100%> (-0.19%) ⬇️

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 f4fba9e...0e90b30. Read the comment docs.

@@ -61,6 +61,7 @@ Bug Fixes

- Bug in :meth:`Index.get_indexer_non_unique` with categorical key (:issue:`21448`)
- Bug in comparison operations for :class:`MultiIndex` where error was raised on equality / inequality comparison involving a MultiIndex with ``nlevels == 1`` (:issue:`21149`)
- The backtrace from a ``KeyError`` is now shorted and clearer (:issue:`21557`)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you be a little more clear here :> (this is when indexing!)

backtrace -> traceback

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should go in 0.24 as this might require a tricky backport (maybe) as the refactored code is in 0.24

@@ -1818,6 +1816,9 @@ def error():
except:
error()

if not ax.contains(key):
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to add a test for this (maybe compare the exception message)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately comparing the message is not enough (it didn't change - and is already tested). We would have to check the traceback, and I have no idea of how to do it - and if we want to do it.

@jreback jreback added this to the 0.24.0 milestone Jun 21, 2018
@jreback jreback merged commit 582323b into pandas-dev:master Jun 21, 2018
@jreback
Copy link
Contributor

jreback commented Jun 21, 2018

thanks @toobaz

@toobaz toobaz deleted the keyerror_error branch June 21, 2018 10:03
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
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.

KeyError error message could be less confusing
3 participants