From c97f7f3fb84ff6cd26c7215e4a99b06559dedbb8 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Sat, 6 Nov 2021 21:24:08 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A7=AA=20Add=20failing=20test=20case?= =?UTF-8?q?=20show=20casing=20the=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xarray/tests/test_plot.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 774f90dbb04..0052178ad68 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -754,6 +754,13 @@ def test_slice_in_title(self): title = plt.gca().get_title() assert "d = 10.01" == title + def test_slice_in_title_single_item_array(self): + """Edge case for data of shape (1, N) or (N, 1).""" + darray = self.darray.expand_dims({"d": np.array([10.009])}) + darray.plot.line(x="period") + title = plt.gca().get_title() + assert "d = 10.01" == title + class TestPlotStep(PlotTestCase): @pytest.fixture(autouse=True) From 60002ddb6febf9d7669315b2abd21f41e307d09d Mon Sep 17 00:00:00 2001 From: s-weigand Date: Sat, 6 Nov 2021 21:25:47 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20format=5Fitem=20crash?= =?UTF-8?q?=20when=20value=20array=20of=20shape=20(1,=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xarray/core/formatting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index ab1cde860f9..3f65cce4f68 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -143,7 +143,7 @@ def format_item(x, timedelta_format=None, quote_strings=True): elif isinstance(x, (str, bytes)): return repr(x) if quote_strings else x elif hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating): - return f"{x:.4}" + return f"{x.item():.4}" else: return str(x) From 51b6cd89157defb426cb33afa44124dfbf1fb7bb Mon Sep 17 00:00:00 2001 From: s-weigand Date: Sun, 7 Nov 2021 00:06:11 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9A=20Added=20change=20to=20whats-?= =?UTF-8?q?new.rst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/whats-new.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 0128e70caed..f499cbe3d21 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -34,7 +34,8 @@ Deprecations Bug fixes ~~~~~~~~~ - +- Fix plot.line crash for data of shape ``(1, N)`` in _title_for_slice on format_item (:pull:`5948`). + By `Sebastian Weigand `_. Documentation ~~~~~~~~~~~~~