-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH/CLN: give all AssertionErrors and nose.SkipTest raises an informative message #3730
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
Conversation
@cpcloud only issue I have is that you may have to manually test that each assert works, e.g. the actual exception message doesn't have an error in it (say from the formatting)...not a big deal....but give a quick verify (e.g. maybe temporarily make the assertion test true and see if the message is ok)....don't need tests for this (just a quick verify) |
@jreback no problem i will just eval the ones that have a constructor with string arguments. |
should suffice just to construct the |
no.. that's exactly the issue; unless you explicity test the AssertionError string its in theory possibly to have a formatting error in the error message; which causes it to raise Exception rather than AssertionError this is quite rare, and no need to test the assertions explicity, just a FYI really |
that works fine, assuming df = df[df.msg.map(lambda x: isinstance(x, basestring))]
(df.code + '(' + df.msg.map(repr) + ')').map(eval) # check for construction error this doesn't cover incorrect format strings though...will test those manually i guess although i'm sure i could come up with a stupid way to parse formatting strings that would test this |
oh by formatting i thought u meant code formatting. sorry. it's hard to do this without running test code since it is determined at runtime. e.g., |
no....
since it 'never' triggers then we don't know that the error message actually is a formatting issue but the things you are checking are probably never triggered (and don't merit tests)..... maybe a ways to have your script actually check this somehow? |
There is a slight issue with that
i think all of these are valid assumptions for error msgs, but i would need to check the corner cases of variables holding strings that will be messages. |
that would work |
ok. this is turning into a static analysis tool for exceptions. i wonder if pylint can't do this... |
nah pylint doesn't do this... |
This looks really nice! I'm going to piggy-back on this to bring up another Exception-related item (though it's about try:
df2 = pandas.ga() # some web scrape or other
df.inde == df2.index
except Exception:
#whelp, does this mean the scrape failed here? Whereas, if we tried to default to more descriptive Exceptions where appropriate and/or used the class DataError(IOError, PandasError): pass That way you could be more specific about what you want to catch (and eventually rewrite some of the test cases to cover this as well) + it's backwards-compatible, because checks for Is this worth pursuing? (I'm volunteering to do this.) |
+1 what would be ideal would be ALL exceptions to be listed in say a hierarchy (not deep really), maybe IOError, DataError near the top and best of all descriptions on when to use them then gradually work thru the library and get rid of EXception maybe add tr warning code in here too (or .warnings) module |
darn it @jreback u beat me 2 to it! |
i hate raising |
@jtratner with this script u can see the line and col no of any exception (and its message if any, but doesn't resolve the variables as that would require eval and there aren't that many of those) matching a regex that u providel u can also provide a module if eg u just want to work on core or core.frame |
i need to revisit the discussion @jreback and i had above, i've sort of let this go by the wayside, modulo the fact that i occasionally rebase and push to make sure there are no merge conflicts when i do get back to it |
Well, I was debating running something like (my grep/sed-fu sucks, even though I use vim constantly:P): grep -rl "^\s*raise Exception" ./ | xargs sed -i "s/^(\s*)raise Exception/\1raise PandasError/" and then adding imports from Sidenote - would this make more sense as an issue linked to a Gist [which can have multiple files] instead of a pull request? That way you wouldn't have to keep rebasing and fixing... |
Also, is there a reason to use the |
glad u asked. |
kind of annoying since it makes it hard to differentiate "user" errors from, e.g., sanity checks when developing things, but alas python is not perfect |
@cpcloud so what's the best way to do this? Submit a pull-request with a bunch of Exception changes? |
@jtratner yep. btw u might trying using |
@cpcloud I'm a big fan of ack (especially because it has great vim integration) |
@jreback on exceptions - I'm thinking we could use a Wiki page on pydata/pandas to describe which exceptions should do what, so it's possible to collaboratively edit it and then could move to the contributing docs. |
@jreback 👍 on this and i think a |
consolidate ALL THE THINGS! |
there is a wiki here on GitHub |
@jreback that's what I'm doing right now. Plus, you can write it in ReST, so can be easily moved around. |
yep that's probably what i would do. i like the idea of having to remember only one place from which to import exceptions |
though these are very specific and essentially internal the exceptions we are talking about are ones that a caller of the function might want to intercept maybe leave these alone (but document) what they r for |
That makes sense. (though I noticed that PandasError appears to be defined On Sun, Jun 16, 2013 at 6:36 AM, jreback [email protected] wrote:
|
this now implements the full format spec (including dict printf, regular printf, and ./parse_except.py --validate i could make an API for this so that it could be added to the end of testing ... e.g., it would tell someone where their change introduces a bad (meaning invalid or incompatible with python2.6) format string in an exception |
can we merge this sometime soon? i believe i've added a message to almost every nose skip and definitely to every assertionerror raise |
well rebase it and looks fine to me. going to be some merge conflicts though |
all nose.SkipTest covered as well as assertionerror msgs...would be nice to get this in to avoid the constant merge conflicts |
if not ((len(args) == self._AXIS_LEN)): | ||
raise AssertionError() | ||
if len(args) != self._AXIS_LEN: | ||
raise AssertionError('There must be an argument for each axis, ' |
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 is not an AssertionError, this should be TypeError and could use a brief test.
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.
actually this can just be removed and add 3 pos args ... simplest way
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.
I believe higher than 3dims uses this too
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.
ok
I see...lots of fixups...ok...go ahead |
ENH/CLN: give all AssertionErrors and nose.SkipTest raises an informative message
continuation of #3519 because of a branch rename.
UPDATE: The exception parsing script has been moved to a Gist
This PR partially addresses #3024.
AssertionError
exceptions now have an informative error message in themAssertionErrors
have been converted to differentException
subclasses, where it makes sense, and there's a corresponding test wherever these were changed.nose.SkipTest
exceptions now have an informative message