Skip to content

Commit 564a291

Browse files
max-sixtydcheriankeewis
authored
Fix html repr on non-str keys (pydata#3870)
* fix html repr on non-str keys * whatsnew * Update doc/whats-new.rst Co-Authored-By: keewis <[email protected]> Co-authored-by: Deepak Cherian <[email protected]> Co-authored-by: keewis <[email protected]>
1 parent e8a284f commit 564a291

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

doc/whats-new.rst

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Bug fixes
9494

9595
- Fix :py:meth:`xarray.core.dataset.Dataset.to_zarr` when using `append_dim` and `group`
9696
simultaneously. (:issue:`3170`). By `Matthias Meyer <https://github.com/niowniow>`_.
97+
- Fix html repr on :py:class:`Dataset` with non-string keys (:pull:`3807`).
98+
By `Maximilian Roos <https://github.com/max-sixty>`_.
9799

98100
Documentation
99101
~~~~~~~~~~~~~

xarray/core/formatting_html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def summarize_variable(name, var, is_index=False, dtype=None, preview=None):
9595

9696
cssclass_idx = " class='xr-has-index'" if is_index else ""
9797
dims_str = f"({', '.join(escape(dim) for dim in var.dims)})"
98-
name = escape(name)
98+
name = escape(str(name))
9999
dtype = dtype or escape(str(var.dtype))
100100

101101
# "unique" ids required to expand/collapse subsections

xarray/tests/test_formatting_html.py

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def test_short_data_repr_html(dataarray):
5151
assert data_repr.startswith("array")
5252

5353

54+
def test_short_data_repr_html_non_str_keys(dataset):
55+
ds = dataset.assign({2: lambda x: x["tmin"]})
56+
fh.dataset_repr(ds)
57+
58+
5459
def test_short_data_repr_html_dask(dask_dataarray):
5560
import dask
5661

0 commit comments

Comments
 (0)