Skip to content

Commit

Permalink
Add dt.date to plottable types (#8873)
Browse files Browse the repository at this point in the history
* Add dt.date to plottable types

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add new feature to whats-new.rst

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add test_date_dimension to plot tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add issue to whats-new

* Fix type in whats-new

* Fix 2 more typos in whats-new

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
saschahofmann and pre-commit-ci[bot] committed Mar 29, 2024
1 parent 5bf2cf4 commit 852b7e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
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

0 comments on commit 852b7e6

Please sign in to comment.