-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
CFTimeIndex #1252
Merged
Merged
CFTimeIndex #1252
Changes from 42 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
e1e8223
Start on implementing and testing NetCDFTimeIndex
spencerkclark 6496458
TST Move to using pytest fixtures to structure tests
spencerkclark 675b2f7
Address initial review comments
spencerkclark 7beddc1
Address second round of review comments
spencerkclark 3cf03bc
Fix failing python3 tests
spencerkclark 53b085c
Match test method name to method name
spencerkclark 738979b
Merge branch 'master' of https://github.com/pydata/xarray into NetCDF…
spencerkclark a177f89
First attempts at integrating NetCDFTimeIndex into xarray
spencerkclark 48ec519
Cleanup
spencerkclark 9e76df6
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 2a7b439
Fix DataFrame and Series test failures for NetCDFTimeIndex
spencerkclark b942724
First pass at making NetCDFTimeIndex compatible with #1356
spencerkclark 7845e6d
Merge branch 'master' into NetCDFTimeIndex
spencerkclark a9ed3c8
Address initial review comments
spencerkclark 3e23ed5
Merge branch 'master' into NetCDFTimeIndex
spencerkclark a9f3548
Merge branch 'master' into NetCDFTimeIndex
spencerkclark f00f59a
Restore test_conventions.py
spencerkclark b34879d
Fix failing test in test_utils.py
spencerkclark e93b62d
flake8
spencerkclark 61e8bc6
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 0244f58
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 32d7986
Update for standalone netcdftime
spencerkclark 9855176
Address stickler-ci comments
spencerkclark 8d61fdb
Skip test_format_netcdftime_datetime if netcdftime not installed
spencerkclark 6b87da7
A start on documentation
spencerkclark 812710c
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 3610e6e
Fix failing zarr tests related to netcdftime encoding
spencerkclark 8f69a90
Simplify test_decode_standard_calendar_single_element_non_ns_range
spencerkclark cec909c
Address a couple review comments
spencerkclark 422792b
Use else clause in _maybe_cast_to_netcdftimeindex
spencerkclark de74037
Start on adding enable_netcdftimeindex option
spencerkclark 2993e3c
Continue parametrizing tests in test_coding_times.py
spencerkclark f3438fd
Update time-series.rst for enable_netcdftimeindex option
spencerkclark c35364e
Use :py:func: in rst for xarray.set_options
spencerkclark 08f72dc
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 62ce0ae
Add a what's new entry and test that resample raises a TypeError
spencerkclark ff05005
Merge branch 'master' of https://github.com/pydata/xarray into NetCDF…
spencerkclark 20fea63
Merge branch 'master' into NetCDFTimeIndex
spencerkclark d5a3cef
Move what's new entry to the version 0.10.3 section
spencerkclark e721d26
Add version-dependent pathway for importing netcdftime.datetime
spencerkclark 5e1c4a8
Make NetCDFTimeIndex and date decoding/encoding compatible with datet…
spencerkclark 257f086
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 00e8ada
Merge branch 'master' into NetCDFTimeIndex
spencerkclark c9d0454
Remove logic to make NetCDFTimeIndex compatible with datetime.datetime
spencerkclark f678714
Documentation edits
spencerkclark b03e38e
Ensure proper enable_netcdftimeindex option is used under lazy decoding
spencerkclark 890dde0
Add fix and test for concatenating variables with a NetCDFTimeIndex
spencerkclark 80e05ba
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 13c8358
Further namespace changes due to netcdftime/cftime renaming
spencerkclark ab46798
NetCDFTimeIndex -> CFTimeIndex
spencerkclark 67fd335
Documentation updates
spencerkclark 7041a8d
Only allow use of CFTimeIndex when using the standalone cftime
spencerkclark 9df4e11
Fix errant what's new changes
spencerkclark 9391463
flake8
spencerkclark da12ecd
Fix skip logic in test_cftimeindex.py
spencerkclark a6997ec
Use only_use_cftime_datetimes option in num2date
spencerkclark 7302d7e
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 9dc5539
Require standalone cftime library for all new functionality
spencerkclark 1aa8d86
Improve skipping logic in test_cftimeindex.py
spencerkclark ef3f2b1
Fix skipping logic in test_cftimeindex.py for when cftime or netcdftime
spencerkclark 4fb5a90
Fix skip logic in Python 3.4 build for test_cftimeindex.py
spencerkclark 1fd205a
Improve error messages when for when the standalone cftime is not ins…
spencerkclark 58a0715
Tweak skip logic in test_accessors.py
spencerkclark ca4d7dd
flake8
spencerkclark 3947aac
Address review comments
spencerkclark a395db0
Temporarily remove cftime from py27 build environment on windows
spencerkclark 1b00bde
flake8
spencerkclark 5fdcd20
Install cftime via pip for Python 2.7 on Windows
spencerkclark 459211c
Merge branch 'master' into NetCDFTimeIndex
spencerkclark 7e9bb20
flake8
spencerkclark 247c9eb
Remove unnecessary new lines; simplify _maybe_cast_to_cftimeindex
spencerkclark e66abe9
Restore test case for #2002 in test_coding_times.py
spencerkclark f25b0b6
Tweak dates out of range warning logic slightly to preserve current d…
spencerkclark b10cc73
Merge branch 'master' into NetCDFTimeIndex
spencerkclark c318755
Address review comments
spencerkclark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,10 @@ You can manual decode arrays in this form by passing a dataset to | |
One unfortunate limitation of using ``datetime64[ns]`` is that it limits the | ||
native representation of dates to those that fall between the years 1678 and | ||
2262. When a netCDF file contains dates outside of these bounds, dates will be | ||
returned as arrays of ``netcdftime.datetime`` objects. | ||
returned as arrays of ``netcdftime.datetime`` objects and a ``NetCDFTimeIndex`` | ||
can be used for indexing. The ``NetCDFTimeIndex`` enables only a subset of | ||
the indexing functionality of a ``pandas.DatetimeIndex``. See | ||
:ref:`NetCDFTimeIndex` for more information. | ||
|
||
Datetime indexing | ||
----------------- | ||
|
@@ -207,3 +210,90 @@ Dataset and DataArray objects with an arbitrary number of dimensions. | |
|
||
For more examples of using grouped operations on a time dimension, see | ||
:ref:`toy weather data`. | ||
|
||
|
||
.. _NetCDFTimeIndex: | ||
|
||
Non-standard calendars and dates outside the Timestamp-valid range | ||
------------------------------------------------------------------ | ||
|
||
Through the optional ``netcdftime`` library and a custom subclass of | ||
``pandas.Index``, xarray supports a subset of the indexing functionality enabled | ||
through the standard ``pandas.DatetimeIndex`` for dates from non-standard | ||
calendars or dates using a standard calendar, but outside the | ||
`Timestamp-valid range`_ (approximately between years 1678 and 2262). This | ||
behavior has not yet been turned on by default; to take advantage of this | ||
functionality, you must have the ``enable_netcdftimeindex`` option set to | ||
``True`` within your context (see :py:func:`~xarray.set_options` for more | ||
information). | ||
|
||
For instance, you can create a DataArray indexed by a time | ||
coordinate with a no-leap calendar within a context manager setting the | ||
``enable_netcdftimeindex`` option, and the time index will be cast to a | ||
``NetCDFTimeIndex``: | ||
|
||
.. ipython:: python | ||
|
||
from itertools import product | ||
from netcdftime import DatetimeNoLeap | ||
|
||
dates = [DatetimeNoLeap(year, month, 1) for year, month in | ||
product(range(1, 3), range(1, 13))] | ||
with xr.set_options(enable_netcdftimeindex=True): | ||
da = xr.DataArray(np.arange(24), coords=[dates], dims=['time'], | ||
name='foo') | ||
|
||
.. note:: | ||
|
||
With the ``enable_netcdftimeindex`` option activated, a ``NetCDFTimeIndex`` | ||
will be used for time indexing if any of the following are true: | ||
|
||
- The dates are from a non-standard calendar | ||
- Any dates are outside the Timestamp-valid range | ||
|
||
Otherwise a ``pandas.DatetimeIndex`` will be used. In addition, if any | ||
variable (not just an index variable) is encoded using a non-standard | ||
calendar, its times will be decoded into ``netcdftime.datetime`` objects, | ||
regardless of whether or not they can be represented using | ||
``np.datetime64[ns]`` objects. | ||
|
||
For data indexed by a ``NetCDFTimeIndex`` xarray currently supports `partial | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe change this to bullet points rather than one long sentence? I.e. "...currently supports: " followed by one bullet each for partial datetime string indexing, dt accessor, groupby, and serialization. |
||
datetime string indexing`_ using strictly `ISO 8601-format`_ partial datetime | ||
strings: | ||
|
||
.. ipython:: python | ||
|
||
da.sel(time='0001') | ||
da.sel(time=slice('0001-05', '0002-02')) | ||
|
||
access of basic datetime components via the ``dt`` accessor (in this case just | ||
"year", "month", "day", "hour", "minute", "second", "microsecond", and "season"): | ||
|
||
.. ipython:: python | ||
|
||
da.time.dt.year | ||
da.time.dt.month | ||
da.time.dt.season | ||
|
||
group-by operations based on datetime accessor attributes (e.g. by month of the | ||
year): | ||
|
||
.. ipython:: python | ||
|
||
da.groupby('time.month').sum() | ||
|
||
and serialization: | ||
|
||
.. ipython:: python | ||
|
||
da.to_netcdf('example.nc') | ||
xr.open_dataset('example.nc') | ||
|
||
.. note:: | ||
|
||
Currently resampling along the time dimension for data indexed by a | ||
``NetCDFTimeIndex`` is not supported. | ||
|
||
.. _Timestamp-valid range: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#timestamp-limitations | ||
.. _ISO 8601-format: https://en.wikipedia.org/wiki/ISO_8601 | ||
.. _partial datetime string indexing: https://pandas.pydata.org/pandas-docs/stable/timeseries.html#partial-string-indexing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might add that it will be enabled in v0.11.