Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WIP/ENH: negative and large datetimes#15148

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

jklymak
Copy link
Member

PR Summary

This is a WIP, but for discussion as to whether this is worth the extra code.

It is easy to make negative datetime64 objects, or large datetime64 objects that are greater than 10000 years, whereas right now we restrict to between year 1 and 9999 because we usedatetime.datetime.

The obvious solution is to usedatetime64, but that falls down because a) we want to be able to deal with timezones, anddatetime64 doesn't by default. b) we want to usedateutil.rrule for things like "put a tick every other Wednesday".

So, the solution proposed here is to derive a subclass ofdatetime that keeps track of more years than 1-9999 (I'm not actually clear whydatetime restricts to these values in the first place). I've attempted (probably poorly) to make the subclass as minimal as possible, and to call the super as often as possible.

import matplotlib.pyplot as pltimport numpy as npfig, ax = plt.subplots()dates = np.arange('-20000-01-01', '-20000-02-01', 10, dtype='datetime64[h]')y = np.arange(len(dates))ax.plot(dates, y, 'd')plt.show()

Before

ValueError: view limit minimum -7305216.541666667 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units

This PR:

CDF

  • Make tests with this feature.
  • write up docs....

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 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

if not isinstance(vmax, _datetimey):
vmax = _datetimey._datetime_to_datetimey(vmax, 0)
vmind, vmaxd = _datetimey._datetimey_to_datetime_samey0(vmin, vmax)
self.rule.set(dtstart=vmind, until=vmaxd)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Note that in the old codedstart=vmin-(vmax-vmin) for some reason, anddstop = vmax + (vmax - vmin). Expanding the range by a factor of three doesn't make much sense to me. The test that changed (test_DateFormatter), in my opinion, changed for the better. So this is a mildly breaking change, but it gives far more consistent results.

@@ -206,6 +207,151 @@ def _get_rc_timezone():
MO, TU, WE, TH, FR, SA, SU)
WEEKDAYS = (MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY)

class _datetimey(datetime.datetime):
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

my guess is that this whole class should go in its own file...

@timhoffm
Copy link
Member

Is this still relevant, now that we can set the epoch?

@jklymak
Copy link
MemberAuthor

Yeah, because it works around datetime's issues with years > 9999 and less than 0.datetime64 has no issues with those (other than typical calendar craziness) so it would be nice to do something. But was waiting for the epoch stuff to shake out first.

@jklymakjklymak modified the milestones:v3.3.0,v3.4.0May 4, 2020
@QuLogicQuLogic removed this from thev3.4.0 milestoneMar 16, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@jklymak@timhoffm@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp