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

CFTimeIndex calendar in repr #4092

Merged
merged 37 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0bd61d9
add property
May 25, 2020
28cbf84
test repr skip
May 25, 2020
c5d36cc
repr
Jun 3, 2020
8d9ebe0
linting
Jun 3, 2020
c1cac9f
remove unnecessary
Jun 3, 2020
d09092a
remove unnecessary
Jun 3, 2020
59dc912
add quotation marks to calendar
Jun 4, 2020
1fccb53
add length to wrapper
Jun 4, 2020
a52e997
linting
Jun 4, 2020
6d022ea
coords.to_index() if CFTimeIndex
Jun 6, 2020
bf8c5a0
to_index() iff CFTimeIndex
Jun 6, 2020
1e809d0
revert linting
Jun 6, 2020
1bfdc7c
revert linting
Jun 6, 2020
d58cb7d
revert linting
Jun 6, 2020
a0d00ab
to_index in short_data_repr_html
Jun 9, 2020
019d309
refine test and rm prints
Jun 9, 2020
269e967
fix to pass all tests
Jun 9, 2020
68a37c6
revert linting changes
Jun 11, 2020
0907cef
revert to_index()
Jun 12, 2020
a9c048f
require cftime for added test
Jun 12, 2020
fcb48fd
implement format_array_flat repr without commata and multiple lines
Jun 14, 2020
83839ec
reproduce pd.Index repr for CFTimeIndex repr
Jun 15, 2020
e3c8c01
reproduce pd.Index repr for CFTimeIndex repr
Jun 15, 2020
69d000f
sensitive to display_width
Jul 7, 2020
80ca891
rewritte format_cftimeindex_array from template of format_array_flat
Jul 7, 2020
3080d81
bugfix
Jul 7, 2020
b77a2ee
new approach
Jul 15, 2020
1e67f3f
Merge branch 'master' into AS_CFTimeIndex_repr_calendar
aaronspring Jul 15, 2020
d8d54ce
docstring
Jul 15, 2020
4b62406
Merge branch 'AS_CFTimeIndex_repr_calendar' of https://github.com/aar…
Jul 15, 2020
249ae24
attrs spaces fix
Jul 15, 2020
ecef05a
rm pandas test, refactor format_attrs and repr test dedent
Jul 18, 2020
7c31e3a
rm f lint
Jul 18, 2020
683f00c
Pass index to format_attrs instead of attrs dict
spencerkclark Jul 19, 2020
2707409
Update whats-new.rst
spencerkclark Jul 19, 2020
b7552b3
Add docstring for new calendar property
spencerkclark Jul 19, 2020
e8d85db
Update doc/whats-new.rst
spencerkclark Jul 19, 2020
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
6 changes: 6 additions & 0 deletions xarray/coding/cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ def asi8(self):
]
)

@property
def calendar(self):
from .times import infer_calendar_name

return infer_calendar_name(self)

def _round_via_method(self, freq, method):
"""Round dates using a specified method."""
from .cftime_offsets import CFTIME_TICKS, to_offset
Expand Down
27 changes: 27 additions & 0 deletions xarray/tests/test_cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,33 @@ def test_cftimeindex_shift_invalid_freq():
index.shift(1, 1)


@requires_cftime
@pytest.mark.parametrize("calendar", _CFTIME_CALENDARS)
def test_cftimeindex_calendar_property(calendar):
index = xr.cftime_range(start="2000", periods=3, calendar=calendar)
# is this awkward here in a test?
aaronspring marked this conversation as resolved.
Show resolved Hide resolved
if calendar == "365_day":
calendar = "noleap"
elif calendar == "366_day":
calendar = "all_leap"
assert index.calendar == calendar


@requires_cftime
@pytest.mark.parametrize("calendar", _CFTIME_CALENDARS)
@pytest.mark.skip(reason="not implemented")
def test_cftimeindex_calendar_in_repr(calendar):
index = xr.cftime_range(start="2000", periods=3, calendar=calendar)
# is this awkward here in a test?
repr_str = index.__repr__()
if calendar == "365_day":
calendar = "noleap"
elif calendar == "366_day":
calendar = "all_leap"
assert calendar in repr_str
assert "calendar=" in repr_str


@requires_cftime
def test_parse_array_of_cftime_strings():
from cftime import DatetimeNoLeap
Expand Down