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

Add dt.date to plottable types #8873

Merged
merged 13 commits into from
Mar 29, 2024
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 @@ -37,6 +37,8 @@ New Features
- Allow creating :py:class:`xr.Coordinates` objects with no indexes (:pull:`8711`)
By `Benoit Bovy <https://github.com/benbovy>`_ and `Tom Nicholas
<https://github.com/TomNicholas>`_.
- Enable plotting of ``datetime.dates``. (:issue:`8866`, :pull:`8873`)
By `Sascha Hofmann <https://github.com/saschahofmann>`_.

Breaking changes
~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import textwrap
import warnings
from collections.abc import Hashable, Iterable, Mapping, MutableMapping, Sequence
from datetime import datetime
from datetime import date, datetime
from inspect import getfullargspec
from typing import TYPE_CHECKING, Any, Callable, Literal, overload

Expand Down Expand Up @@ -672,7 +672,7 @@ def _ensure_plottable(*args) -> None:
np.bool_,
np.str_,
)
other_types: tuple[type[object], ...] = (datetime,)
other_types: tuple[type[object], ...] = (datetime, date)
cftime_datetime_types: tuple[type[object], ...] = (
() if cftime is None else (cftime.datetime,)
)
Expand Down
14 changes: 13 additions & 1 deletion xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import math
from collections.abc import Hashable
from copy import copy
from datetime import datetime
from datetime import date, datetime, timedelta
from typing import Any, Callable, Literal

import numpy as np
Expand Down Expand Up @@ -620,6 +620,18 @@ def test_datetime_dimension(self) -> None:
ax = plt.gca()
assert ax.has_data()

def test_date_dimension(self) -> None:
nrow = 3
ncol = 4
start = date(2000, 1, 1)
time = [start + timedelta(days=i) for i in range(nrow)]
a = DataArray(
easy_array((nrow, ncol)), coords=[("time", time), ("y", range(ncol))]
)
a.plot()
ax = plt.gca()
assert ax.has_data()

@pytest.mark.slow
@pytest.mark.filterwarnings("ignore:tight_layout cannot")
def test_convenient_facetgrid(self) -> None:
Expand Down
Loading