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

Convert ref_date to UTC in encode_cf_datetime #2651

Merged
merged 2 commits into from
Jan 5, 2019

Conversation

spencerkclark
Copy link
Member

@spencerkclark spencerkclark commented Jan 4, 2019

I think this should be an appropriate fix for #2649, but I'd appreciate input from those who are more experienced dealing with timezones in NumPy/pandas.

My understanding is that NumPy dates are stored as UTC and do not carry any timezone information. Therefore converting the ref_date with tz_convert(None) here, which converts it to UTC and removes the timezone information, should be appropriate for encoding.

@shoyer
Copy link
Member

shoyer commented Jan 5, 2019

Is there a CF convention for time zones?

Numpy’s datetime objects are time zone agnostic (often, but not necessarily UTC). It seems a little dangerous to assume a time zone.

@shoyer
Copy link
Member

shoyer commented Jan 5, 2019

I looked up CF conventions -- see my comment in #2649.

I'm pretty sure this is the right fix here, so I'm going to merge this.

@shoyer shoyer merged commit 85f88e7 into pydata:master Jan 5, 2019
@spencerkclark spencerkclark deleted the fix-2649 branch January 5, 2019 19:07
@shoyer shoyer mentioned this pull request Jan 6, 2019
3 tasks
dcherian pushed a commit to yohai/xarray that referenced this pull request Jan 24, 2019
* master:
  Remove broken Travis-CI builds (pydata#2661)
  Type checking with mypy (pydata#2655)
  Added Coarsen (pydata#2612)
  Improve test for GH 2649 (pydata#2654)
  revise top-level package description (pydata#2430)
  Convert ref_date to UTC in encode_cf_datetime (pydata#2651)
  Change an `==` to an `is`. Fix tests so that this won't happen again. (pydata#2648)
  ENH: switch Dataset and DataArray to use explicit indexes (pydata#2639)
  Use pycodestyle for lint checks. (pydata#2642)
  Switch whats-new for 0.11.2 -> 0.11.3
  DOC: document v0.11.2 release
  Use built-in interp for interpolation with resample (pydata#2640)
  BUG: pytest-runner no required for setup.py (pydata#2643)
shoyer pushed a commit that referenced this pull request Jan 24, 2019
* Convert ref_date to UTC in encode_cf_datetime

* Only convert ref_date if it is not timezone-naive
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.

"Timestamp subtraction must have the same timezones or no timezones" when saving a NetCDF
2 participants