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

Fixed assertion error message #5242

Merged
merged 1 commit into from
Oct 16, 2013
Merged

Fixed assertion error message #5242

merged 1 commit into from
Oct 16, 2013

Conversation

ojh
Copy link
Contributor

@ojh ojh commented Oct 16, 2013

This is a pretty straightforward fix, message was simply inverted.

jreback added a commit that referenced this pull request Oct 16, 2013
Fixed assertion error message
@jreback jreback merged commit d731229 into pandas-dev:master Oct 16, 2013
@jreback
Copy link
Contributor

jreback commented Oct 16, 2013

thanks!

@jtratner
Copy link
Contributor

did you actually see this error? how?

@ojh
Copy link
Contributor Author

ojh commented Oct 16, 2013

@jtratner It came up as part of a traceback in some code I was debugging... Was a pretty weird error to try to make sense of:

AssertionError: Truncate: 2012-10-02 14:51:00 must be after 2012-10-02 14:50:50

Err... Yeah? ;)

@jreback
Copy link
Contributor

jreback commented Oct 16, 2013

@ojh can you post code that generated it? maybe need a test for it......

@jtratner
Copy link
Contributor

The reason we're asking is because if you see an AssertionError, the logic
is probably screwed up somewhere upstream (i.e., some function isn't
checking for bad input or is passing arguments wrong). Generally, users
should never see assertion errors.

@ojh
Copy link
Contributor Author

ojh commented Oct 17, 2013

@jreback @jtratner Sorry for the slow response, it was late when I posted this last night, and I've been busy all morning today...

The code I was dealing with is a bit hairy, but the following should illustrate the issue clearly enough:

import numpy, pandas

rng = pandas.date_range('1/1/2011', periods=72, freq='H')
ts = pandas.Series(numpy.random.randn(len(rng)), index=rng)

ts.truncate(before='10/31/2011', after='12/31/2011') # No problem here

ts.truncate(before='12/31/2011', after='10/31/2011') # Switched dates, to illustrate

That last line then throws the following error (which is pretty much what I would expect, except that the order of the dates is wrong in the message):

AssertionError: Truncate: 2011-12-31 00:00:00 must be after 2011-10-31 00:00:00

The author of the actual code which resulted in this had assumed that the dates he was reading in would always be in chronological order - turns out this wasn't the case in one particular CSV file that got imported... Obviously, this has now been fixed with an appropriate failsafe added. I fully agree that users should never see assertion errors, but the confusing error message made the issue harder to debug for me, so I figured it might save someone else the confusion in future.

@jtratner
Copy link
Contributor

Thanks - that's helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants