Skip to content

FIX: allow zero and one as dates via wrapping #15416

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 1 commit into from

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Oct 14, 2019

PR Summary

Unit converters should not simply fail if given legitimate floating point numbers. Right now num2date fails if x<1, and that causes problems like #15409 because our default axes limits are 0, 1.

This PR simply wraps the date to a valid date between 1 and 3652059 days. This means that the default [0, 1] maps to [9999-12-31, 0001-01-01], which is nonsense, but its perhaps better than errorring out.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@dstansby
Copy link
Member

I agree that converters shouldn't fail, but I think with these changes they give very misleading/nonsense answers which is worse! Maybe I'm missing something though - is there a larger motivation to make this change other than just "converters shouldn't fail"?

@jklymak
Copy link
Member Author

jklymak commented Oct 14, 2019

We have times where an axes is dates but during draw gets temporarily set back to default limits of zero and one. This errors out. See #15409 for the latest incantation of this problem but there have been quite a few.

This suggestion does return nonesense if the user somehow uses the wrong x/ylimits or puts bad data on the date axis. Right now we error if the data is bad enough (ie x<1) but not if it’s sort of bad (x>1).

See #15148 for a different approach. But we really can’t be in a position where a unit converter throws errors on zero.

@jklymak
Copy link
Member Author

jklymak commented Oct 14, 2019

Of course the other option is to change the epoch so zero isn’t year 0001. See #15008.

@tacaswell
Copy link
Member

This can invert the direction of the axis, I don't recall off the top of my head how 'sticky' that is.

@efiring
Copy link
Member

efiring commented Oct 22, 2019

If the problem is the default [0, 1], how about changing that to [1, 2] or [1, 10], or ...?

@jklymak
Copy link
Member Author

jklymak commented Oct 22, 2019

The 0-1 default is the default for all axes. I guess we could change that, but folks who make an axes and position text on it by data position will find their code broken.

@efiring
Copy link
Member

efiring commented Oct 22, 2019

I don't like the nonsense aspect of this solution; my reaction is the same as @dstansby's, that this cure is worse than the disease.

@jklymak
Copy link
Member Author

jklymak commented Oct 22, 2019

My strong preference is that we change the epoch.

@jklymak
Copy link
Member Author

jklymak commented Oct 26, 2019

I'll close this as a bit of a silly idea, however, I still think we should do #15008

@jklymak jklymak closed this Oct 26, 2019
@jklymak jklymak deleted the fix-allow-zero-one-dates branch October 26, 2019 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants