From 1537df12f1777ee18d7e90ed6a0049817cb7eaaa Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Mon, 25 Mar 2024 10:04:53 +0100 Subject: [PATCH 1/9] Add dt.date to plottable types --- xarray/plot/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 804e1cfd795..66f690bb690 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -4,7 +4,7 @@ import textwrap import warnings from collections.abc import Hashable, Iterable, Mapping, MutableMapping, Sequence -from datetime import datetime +from datetime import datetime, date from inspect import getfullargspec from typing import TYPE_CHECKING, Any, Callable, Literal, overload @@ -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,) ) From 2c45c809189eaa5b2225a82ec81b860b41f81ca4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 09:08:03 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/plot/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 66f690bb690..8789bc2f9c2 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -4,7 +4,7 @@ import textwrap import warnings from collections.abc import Hashable, Iterable, Mapping, MutableMapping, Sequence -from datetime import datetime, date +from datetime import date, datetime from inspect import getfullargspec from typing import TYPE_CHECKING, Any, Callable, Literal, overload From 44b4526233d24775f7ecc65d60d35955bb598c33 Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Mon, 25 Mar 2024 10:09:44 +0100 Subject: [PATCH 3/9] Add new feature to whats-new.rst --- doc/whats-new.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index c1bfaba8756..5ba590d983e 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -35,6 +35,9 @@ New Features - Expand use of ``.oindex`` and ``.vindex`` properties. (:pull: `8790`) By `Anderson Banihirwe `_ and `Deepak Cherian `_. +- Enable plotting of ```datetime.dates``. (:pull: `8873`) + By `Sascha Hofmann <`_. + Breaking changes ~~~~~~~~~~~~~~~~ From 8c279322894d12022e266f4b161329622515c7c8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 09:12:51 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 5ba590d983e..14d16f80c58 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -37,7 +37,7 @@ New Features - Enable plotting of ```datetime.dates``. (:pull: `8873`) By `Sascha Hofmann <`_. - + Breaking changes ~~~~~~~~~~~~~~~~ From f35c18912f737db0eb6367eb4dd440a8f47b8cf4 Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Thu, 28 Mar 2024 08:57:13 +0100 Subject: [PATCH 5/9] Add test_date_dimension to plot tests --- xarray/tests/test_plot.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 6f983a121fe..bc55bd021f0 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -5,7 +5,7 @@ import math from collections.abc import Hashable from copy import copy -from datetime import datetime +from datetime import datetime, date, timedelta from typing import Any, Callable, Literal import numpy as np @@ -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: From cfdc7fe5bbbf0bf5526d62a74cbea17952ab8056 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 07:58:20 +0000 Subject: [PATCH 6/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/tests/test_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index bc55bd021f0..8da1bba6207 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -5,7 +5,7 @@ import math from collections.abc import Hashable from copy import copy -from datetime import datetime, date, timedelta +from datetime import date, datetime, timedelta from typing import Any, Callable, Literal import numpy as np @@ -624,7 +624,7 @@ 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)] + time = [start + timedelta(days=i) for i in range(nrow)] a = DataArray( easy_array((nrow, ncol)), coords=[("time", time), ("y", range(ncol))] ) From 6f39ba29974360d08491aa76db7b26e133328010 Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Thu, 28 Mar 2024 09:09:21 +0100 Subject: [PATCH 7/9] Add issue to whats-new --- doc/whats-new.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index c3013be8b68..7648fef9b4b 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -37,8 +37,7 @@ New Features - Allow creating :py:class:`xr.Coordinates` objects with no indexes (:pull:`8711`) By `Benoit Bovy `_ and `Tom Nicholas `_. - -- Enable plotting of ```datetime.dates``. (:pull: `8873`) +- Enable plotting of ```datetime.dates``. (:issue:`8866`, :pull: `8873`) By `Sascha Hofmann <`_. Breaking changes From 9c0a2e93659e11d73c33ae5e2def7776e0c90441 Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Thu, 28 Mar 2024 09:35:42 +0100 Subject: [PATCH 8/9] Fix type in whats-new --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 7648fef9b4b..ccb18e37a18 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -37,7 +37,7 @@ New Features - Allow creating :py:class:`xr.Coordinates` objects with no indexes (:pull:`8711`) By `Benoit Bovy `_ and `Tom Nicholas `_. -- Enable plotting of ```datetime.dates``. (:issue:`8866`, :pull: `8873`) +- Enable plotting of ``datetime.dates``. (:issue:`8866`, :pull: `8873`) By `Sascha Hofmann <`_. Breaking changes From 7c2625f24441dda94ac59d26d5f2f380443409ba Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Thu, 28 Mar 2024 09:59:09 +0100 Subject: [PATCH 9/9] Fix 2 more typos in whats-new --- doc/whats-new.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index ccb18e37a18..aa58a982973 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -37,8 +37,8 @@ New Features - Allow creating :py:class:`xr.Coordinates` objects with no indexes (:pull:`8711`) By `Benoit Bovy `_ and `Tom Nicholas `_. -- Enable plotting of ``datetime.dates``. (:issue:`8866`, :pull: `8873`) - By `Sascha Hofmann <`_. +- Enable plotting of ``datetime.dates``. (:issue:`8866`, :pull:`8873`) + By `Sascha Hofmann `_. Breaking changes ~~~~~~~~~~~~~~~~