diff --git a/xarray/core/formatting_html.py b/xarray/core/formatting_html.py index 9730a0a1745..5c2d2210ebd 100644 --- a/xarray/core/formatting_html.py +++ b/xarray/core/formatting_html.py @@ -39,7 +39,7 @@ def format_dims(dims, coord_names): } dims_li = "".join( - f"
  • " f"{escape(dim)}: {size}
  • " + f"
  • " f"{escape(str(dim))}: {size}
  • " for dim, size in dims.items() ) @@ -48,7 +48,7 @@ def format_dims(dims, coord_names): def summarize_attrs(attrs): attrs_dl = "".join( - f"
    {escape(k)} :
    " f"
    {escape(str(v))}
    " + f"
    {escape(str(k))} :
    " f"
    {escape(str(v))}
    " for k, v in attrs.items() ) diff --git a/xarray/tests/test_formatting_html.py b/xarray/tests/test_formatting_html.py index 4cf4509c7eb..47640ef2d95 100644 --- a/xarray/tests/test_formatting_html.py +++ b/xarray/tests/test_formatting_html.py @@ -181,3 +181,29 @@ def test_variable_repr_html(): # Just test that something reasonable was produced. assert html.startswith("") assert "xarray.Variable" in html + + +def test_repr_of_nonstr_dataset(dataset): + ds = dataset.copy() + ds.attrs[1] = "Test value" + ds[2] = ds["tmin"] + formatted = fh.dataset_repr(ds) + assert "
    1 :
    Test value
    " in formatted + assert "
    2" in formatted + + +def test_repr_of_nonstr_dataarray(dataarray): + da = dataarray.rename(dim_0=15) + da.attrs[1] = "value" + formatted = fh.array_repr(da) + assert "
    1 :
    value
    " in formatted + assert "
  • 15: 4
  • " in formatted + + +def test_nonstr_variable_repr_html(): + v = xr.Variable(["time", 10], [[1, 2, 3], [4, 5, 6]], {22: "bar"}) + assert hasattr(v, "_repr_html_") + with xr.set_options(display_style="html"): + html = v._repr_html_().strip() + assert "
    22 :
    bar
    " in html + assert "
  • 10: 3
  • " in html