diff --git a/xarray/core/formatting_html.py b/xarray/core/formatting_html.py index b03ecc12962..dbebbcf4fbe 100644 --- a/xarray/core/formatting_html.py +++ b/xarray/core/formatting_html.py @@ -96,7 +96,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) - dtype = dtype or var.dtype + dtype = dtype or escape(str(var.dtype)) # "unique" ids required to expand/collapse subsections attrs_id = "attrs-" + str(uuid.uuid4()) diff --git a/xarray/tests/test_formatting_html.py b/xarray/tests/test_formatting_html.py index e7f54b22d06..fea24ff93f8 100644 --- a/xarray/tests/test_formatting_html.py +++ b/xarray/tests/test_formatting_html.py @@ -130,3 +130,5 @@ def test_repr_of_dataset(dataset): assert ( formatted.count("class='xr-section-summary-in' type='checkbox' checked>") == 3 ) + assert "<U4" in formatted + assert "<IA>" in formatted