Skip to content

BUG: PandasAutoDateLocator num_days calculation is wrong #15753

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
dadkins opened this issue Mar 20, 2017 · 7 comments
Closed

BUG: PandasAutoDateLocator num_days calculation is wrong #15753

dadkins opened this issue Mar 20, 2017 · 7 comments
Labels
Milestone

Comments

@dadkins
Copy link

dadkins commented Mar 20, 2017

This line in PandasAutoDateLocator looks like it's missing some parentheses.

https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/converter.py#L264
num_days = ((delta.years * 12.0) + delta.months * 31.0) + delta.days

I stepped through here and with a delta of 5 years, num_days was 60! It's easy enough to fix:

    num_days = (((delta.years * 12.0) + delta.months) * 31.0) + delta.days
@jorisvandenbossche
Copy link
Member

That indeed seems to be the case.

Do you have a plot example that shows 'incorrect' behaviour because of this? That would make it possible to check that it actually changes the look in a positive way

@mroeschke
Copy link
Member

Looks like PR 14716 addressed this but stalled.

@jorisvandenbossche
Copy link
Member

Good catch.
Maybe we should just merge it, without a test / example of visual change, as it is clearly a mistake in the code. Although a confirmation with an actual example which improves due to this change would still be useful.

@jorisvandenbossche
Copy link
Member

Actually, looking at that code, I don't think we are going to find an example:

num_days = ((delta.years * 12.0) + delta.months * 31.0) + delta.days
num_sec = (delta.hours * 60.0 + delta.minutes) * 60.0 + delta.seconds
tot_sec = num_days * 86400. + num_sec

if abs(tot_sec) < self.minticks:
    ....

tot_sec (and thus num_days) is only used to check whether it is smaller than minticks which is typically a number like 5. So once you have hours, let alone years, of data, the tot_sec will always be a huge number.
@mroeschke Or am I missing something?

@mroeschke
Copy link
Member

Not too familiar with this section of the codebase, but agreed that this shouldn't have an obvious change. The if abs(tot_sec) < self.minticks: block just looks like it's adjusting the axis to plot data that spans maybe seconds(?), in which case num_days would be 0 if triggered (which occurs with the current code and the proposed change.)

@jorisvandenbossche
Copy link
Member

I merged the PR, so this can be closed.
@dadkins Thanks for the report

@jorisvandenbossche jorisvandenbossche added this to the 0.20.0 milestone Mar 21, 2017
@dadkins
Copy link
Author

dadkins commented Mar 21, 2017

Thank you for the quick fix.

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

No branches or pull requests

3 participants