Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Bug fixes

- Fix Pydap Datatree backend testing. Testing now compares elements of (unordered) two sets (before, lists) (:pull:`10525`).
By `Miguel Jimenez-Urias <https://github.com/Mikejmnez>`_.
- Fix ``KeyError`` when passing a ``dim`` argument different from the default to ``convert_calendar`` (:pull:`10544`).
By `Eric Jansen <https://github.com/ej81>`_.


Documentation
Expand Down
2 changes: 1 addition & 1 deletion xarray/coding/calendar_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def convert_calendar(
out[dim] = new_times

# Remove NaN that where put on invalid dates in target calendar
out = out.sel(time=out[dim].notnull())
out = out.sel({dim: out[dim].notnull()})

if use_cftime:
# Reassign times to ensure time index of output is a CFTimeIndex
Expand Down
12 changes: 12 additions & 0 deletions xarray/tests/test_calendar_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ def test_convert_calendar_errors():
convert_calendar(da, "standard", dim="x")


def test_convert_calendar_dimension_name():
src = DataArray(
date_range("2004-01-01", "2004-01-31", freq="D", calendar="noleap"),
dims=("date",),
name="date",
)

out = convert_calendar(src, "proleptic_gregorian", dim="date")

np.testing.assert_array_equal(src, out)


def test_convert_calendar_same_calendar():
src = DataArray(
date_range("2000-01-01", periods=12, freq="6h", use_cftime=False),
Expand Down
Loading