Skip to content

WIP Add a CFTimeIndex-enabled xr.cftime_range function #2301

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

Merged
merged 23 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
009fbe3
Initial work on adding a cftime-compatible date_range function
spencerkclark Jul 19, 2018
f66ee5c
Allow empty CFTimeIndexes; add calendar to CFTimeIndex repr
spencerkclark Jul 22, 2018
4291e5a
Enable CFTimeIndex constructor to optionally take date_range arguments
spencerkclark Jul 22, 2018
5c6abfc
Simplify date_range to use new CFTimeIndex constructor
spencerkclark Jul 22, 2018
ae9e55c
Rename xr.date_range to xr.cftime_range
spencerkclark Aug 3, 2018
c702ff5
Merge branch 'master' into date-range
spencerkclark Aug 3, 2018
d96f82d
Follow pandas behavior/naming for rollforward, rollback, and onOffset
spencerkclark Aug 4, 2018
953154a
Merge branch 'master' into date-range
spencerkclark Aug 30, 2018
30d6d92
Update docstring
spencerkclark Aug 30, 2018
058211f
Merge branch 'master' into date-range
spencerkclark Sep 1, 2018
059cd42
Add pandas copyright notice to cftime_offsets.py
spencerkclark Sep 14, 2018
0ff8299
Check validity of offset constructor arguments
spencerkclark Sep 14, 2018
d9a07cc
Fix TypeError versus ValueError uses
spencerkclark Sep 14, 2018
663c7c6
Use a module-level importorskip in test_cftime_offsets.py
spencerkclark Sep 14, 2018
3e2743e
Only return a CFTimeIndex from cftime_range
spencerkclark Sep 14, 2018
cbb52dc
Keep CFTimeIndex constructor simple
spencerkclark Sep 14, 2018
d14a60b
Add some explicitly calendar-specific tests
spencerkclark Sep 14, 2018
885135a
Revert back to default repr
spencerkclark Sep 14, 2018
cc1e45d
lint
spencerkclark Sep 14, 2018
04bc5f6
return NotImplemented
spencerkclark Sep 14, 2018
abd53b0
Convert pandas copyright notices to comments
spencerkclark Sep 14, 2018
6802471
test_calendar_leap_year_length -> test_calendar_year_length
spencerkclark Sep 14, 2018
19c1dfe
Use return NotImplemented in __apply__ too
spencerkclark Sep 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ Custom Indexes

CFTimeIndex

Creating custom indexes
-----------------------
.. autosummary::
:toctree: generated/

cftime_range

Plotting
========

Expand Down
11 changes: 10 additions & 1 deletion doc/time-series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,16 @@ coordinate with a no-leap calendar within a context manager setting the
calendar, its times will be decoded into ``cftime.datetime`` objects,
regardless of whether or not they can be represented using
``np.datetime64[ns]`` objects.


xarray also includes a :py:func:`cftime_range` function, which enables creating a
``CFTimeIndex`` with regularly-spaced dates. For instance, we can create the
same dates and DataArray we created above using:

.. ipython:: python

dates = xr.cftime_range(start='0001', periods=24, freq='MS', calendar='noleap')
da = xr.DataArray(np.arange(24), coords=[dates], dims=['time'], name='foo')

For data indexed by a ``CFTimeIndex`` xarray currently supports:

- `Partial datetime string indexing`_ using strictly `ISO 8601-format`_ partial
Expand Down
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Enhancements
now displayed as `a b ... y z` rather than `a b c d ...`.
(:issue:`1186`)
By `Seth P <https://github.com/seth-p>`_.
- A new CFTimeIndex-enabled :py:func:`cftime_range` function for use in
generating dates from standard or non-standard calendars. By `Spencer Clark
<https://github.com/spencerkclark>`_.

- When interpolating over a ``datetime64`` axis, you can now provide a datetime string instead of a ``datetime64`` object. E.g. ``da.interp(time='1991-02-01')``
(:issue:`2284`)
Expand Down
1 change: 1 addition & 0 deletions xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from .conventions import decode_cf, SerializationWarning

from .coding.cftime_offsets import cftime_range
from .coding.cftimeindex import CFTimeIndex

from .util.print_versions import show_versions
Expand Down
Loading