Skip to content

CLN: remove bare excepts #14700

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

Closed
wants to merge 2 commits into from
Closed

CLN: remove bare excepts #14700

wants to merge 2 commits into from

Conversation

clham
Copy link
Contributor

@clham clham commented Nov 20, 2016

Errors in indexing no longer forced into KeyError

@codecov-io
Copy link

codecov-io commented Nov 20, 2016

Current coverage is 84.55% (diff: 0.00%)

Merging #14700 into master will not change coverage

@@             master     #14700   diff @@
==========================================
  Files           144        144          
  Lines         51043      51043          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits          43160      43160          
  Misses         7883       7883          
  Partials          0          0          

Powered by Codecov. Last update 73bc6cf...6c4b4cd

@@ -1320,8 +1320,8 @@ def _getbool_axis(self, key, axis=0):
inds, = key.nonzero()
try:
return self.obj.take(inds, axis=axis, convert=False)
except Exception as detail:
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of this, catch appropriate errors (and let others bubble up), and convert to the correct exception type. as written this is a big change in the API

@@ -1216,7 +1216,7 @@ def test_loc_getitem_bool(self):
self.check_result('bool', 'loc', b, 'ix', b,
typs=['ints', 'labels', 'mixed', 'ts', 'floats'])
self.check_result('bool', 'loc', b, 'ix', b, typs=['empty'],
fails=KeyError)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a major API change, pls revert

@jreback
Copy link
Contributor

jreback commented Nov 21, 2016

needs the test from the issue

@jreback jreback changed the title BUG: Fixes GH14554 CLN: remove bare excepts Nov 21, 2016
@jreback jreback added Clean Error Reporting Incorrect or improved errors from pandas labels Nov 21, 2016
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

please make the changes as indicated

@clham
Copy link
Contributor Author

clham commented Nov 22, 2016

I'm struggling with the intent of what's going on then.

Indexing errors and key errors should be converted to key error, everything else (like the bug reports recursion error) shouldbubble up? Thanks for the understanding, This is one of my first non doc PRs.

@jreback
Copy link
Contributor

jreback commented Nov 22, 2016

Indexing errors and key errors should be converted to key error, everything else (like the bug reports recursion error) shouldbubble up? Thanks for the understanding, This is one of my first non doc PRs.

no they should be converted to the _exception. you can try just catching IndexError/TypeError where where the bare exceptions are now.

Its very important that the exceptions that are related to indexing are consistent (think from a user perspective). and so we don't/can't change them. However we may have an implementation that actually does positional type things (e.g. .take), which may raise an error for something not found, but (in this case) are doing label indexing so a KeyError is correct, but the same code block may also handle positional indexing (the subclasses define _exception), so the _exception is then IndexError (again for consistency).

raise self._exception
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need an except here (it will default to raising).

you also don't need to catch self._exception

@@ -1218,6 +1222,18 @@ def test_loc_getitem_bool(self):
self.check_result('bool', 'loc', b, 'ix', b, typs=['empty'],
fails=KeyError)

def test_recursion_fails_loc(self):
#GH14554
Copy link
Contributor

Choose a reason for hiding this comment

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

you need a space after the comments

@@ -279,6 +278,11 @@ def _print(result, error=None):
k2 = key2
_eq(t, o, a, obj, key1, k2)

#GH14554: used to make sure recursion errors bubble up as expected
recursive_df = pd.DataFrame({'a':[1,]}, index=['a'])
def recursive_indexing_function(self, a):
Copy link
Contributor

Choose a reason for hiding this comment

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

can we define this inside of the test function?

@clham
Copy link
Contributor Author

clham commented Dec 15, 2016

@jreback What's the best course of action here? Some of the builds are failing, but for conflicting reasons. 3.4 is blowing the stack, 3.5 is failing because it because the recursion limit is being set to low. I've reached an impasse in googling. Something doesn't smell right in artificially setting the setrecursionlimit, but I can't think of another way to ensure the stack doesn't actually overflow before the exception it thrown?

return recursive_indexing_function(
recursive_df[['a'], ['a']])

oldVal=sys.getrecursionlimit()
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you changing the recursion limit at all?
just let the assert happen naturally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I exclude it, when I run the tests, my stack just blows up, and the exception doesn't bubble up.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this seems kind of extreme. why don't you just remove this test and leave your change. pls add a whatsnew note (for 0.20.0), and we'll call it a day :>

of course give it a manual test that things work

@clham
Copy link
Contributor Author

clham commented Dec 17, 2016

@jreback Updated and squashed.

@jreback
Copy link
Contributor

jreback commented Dec 17, 2016

can you rebase and push again. like to see this all green.

@clham
Copy link
Contributor Author

clham commented Dec 17, 2016

My git-foo was all jacked up. I have no idea what happened. Please let me know if current push works.

@jorisvandenbossche
Copy link
Member

@clham Can you push again? For some reason, the tests didn't run

@clham
Copy link
Contributor Author

clham commented Dec 18, 2016

Done. Still seems not to be triggering. Should I try adding a commit?

@jorisvandenbossche
Copy link
Member

Can you fix the merge conflict and in the whatsnew file, and push that?

@clham
Copy link
Contributor Author

clham commented Dec 18, 2016

made a change and repushed: still doesn't appear to be getting pulled into Travis or AppVeyor. Conflict was also resolved. it is only a few small changes. does it make sens to nuke the branch and submit a fresh PR?

@clham
Copy link
Contributor Author

clham commented Dec 18, 2016

resubmitted as #14912 . Just starting over to make the pain stop.

@jreback jreback closed this Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLN/BUG: remove bare excepts
4 participants