From 7c58809148730e5b1fe841e58eb24b440ed43311 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 19 Mar 2020 17:09:35 -0400 Subject: [PATCH 1/3] fix html repr on non-str keys --- xarray/core/formatting_html.py | 2 +- xarray/tests/test_formatting_html.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/xarray/core/formatting_html.py b/xarray/core/formatting_html.py index 8ceda8bfbfa..8678a58b381 100644 --- a/xarray/core/formatting_html.py +++ b/xarray/core/formatting_html.py @@ -95,7 +95,7 @@ def summarize_variable(name, var, is_index=False, dtype=None, preview=None): cssclass_idx = " class='xr-has-index'" if is_index else "" dims_str = f"({', '.join(escape(dim) for dim in var.dims)})" - name = escape(name) + name = escape(str(name)) dtype = dtype or escape(str(var.dtype)) # "unique" ids required to expand/collapse subsections diff --git a/xarray/tests/test_formatting_html.py b/xarray/tests/test_formatting_html.py index 01357000b20..239f339208d 100644 --- a/xarray/tests/test_formatting_html.py +++ b/xarray/tests/test_formatting_html.py @@ -51,6 +51,11 @@ def test_short_data_repr_html(dataarray): assert data_repr.startswith("array") +def test_short_data_repr_html_non_str_keys(dataset): + ds = dataset.assign({2: lambda x: x["tmin"]}) + fh.dataset_repr(ds) + + def test_short_data_repr_html_dask(dask_dataarray): import dask From eb95fa5155a806e848cc113631d90c3e9914adb5 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 19 Mar 2020 17:29:03 -0400 Subject: [PATCH 2/3] whatsnew --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 8140288f350..26f220b11a6 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -88,6 +88,8 @@ Bug fixes - Fix :py:meth:`xarray.core.dataset.Dataset.to_zarr` when using `append_dim` and `group` simultaneously. (:issue:`3170`). By `Matthias Meyer `_. +- Fix html repr on ``Dataset``s with non-string keys (:pull:`3807`). + By `Maximilian Roos `_. Documentation ~~~~~~~~~~~~~ From f09f722775ec990967dbe2a10b9857ae23dd5106 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Fri, 20 Mar 2020 07:19:24 -0600 Subject: [PATCH 3/3] Update doc/whats-new.rst Co-Authored-By: keewis --- 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 26f220b11a6..e37ffcb240a 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -88,7 +88,7 @@ Bug fixes - Fix :py:meth:`xarray.core.dataset.Dataset.to_zarr` when using `append_dim` and `group` simultaneously. (:issue:`3170`). By `Matthias Meyer `_. -- Fix html repr on ``Dataset``s with non-string keys (:pull:`3807`). +- Fix html repr on :py:class:`Dataset` with non-string keys (:pull:`3807`). By `Maximilian Roos `_. Documentation