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

Use np.datetime64[ns] for dates between years 1678 and 2262? #41

Closed
Manangka opened this issue Mar 10, 2019 · 2 comments
Closed

Use np.datetime64[ns] for dates between years 1678 and 2262? #41

Manangka opened this issue Mar 10, 2019 · 2 comments

Comments

@Manangka
Copy link
Collaborator

In GitLab by @Huite on Mar 10, 2019, 15:21

To support years before 1679 and after 2262, dates are converted to cftime objects.
Turns out this isn't ideal, as cftime objects are not nearly as ubiquitous as the np.datetime64[ns] dtype. Currently, neither plotting nor resampling will work out of the box.

The xarray docs mention that for suitable dates, it defaults to np.datetime64[ns], since this integrates nicely with e.g. pandas or matplotlib.
http://xarray.pydata.org/en/stable/time-series.html#creating-datetime64-data

Mentioned there, the following issues address some problems:

I suggest we do the same: I estimate that over 90% of use cases are within the mentioned bounds.
As far as I can tell, there are no good & consistent solutions (yet) for date ranges outside of those bounds: pandas seems pretty stuck to nanosecond resolution. cftime functionality will be expanded to support plotting, but will likely remain a "second-rate" citizen for quite some time. (Just to name an example: lack of real pandas support will mean that xarray's .to_dataframe() method probably be complicated.)

Defaulting to np.datetime64[ns] introduces the least complexity in the most cases: if you're dealing with long timespans, you're going to run into trouble somewhere else anyway.

Concretely, my idea is:

  • If within bounds, return np.datetime64
  • Else, return cftime, since it supports a good bit of xarray functionality (with 0.12 release)
  • Add a use_cftime option to idf.load, similar to: Add use_cftime option to open_dataset pydata/xarray#2759, so all DataArrays have consistent datetimes, when you're working with long timespans.
@Manangka
Copy link
Collaborator Author

In GitLab by @visr on Mar 10, 2019, 19:24

closed via merge request !20

@Manangka
Copy link
Collaborator Author

In GitLab by @visr on Mar 10, 2019, 19:24

mentioned in commit 0f723eb

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

No branches or pull requests

1 participant