-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
Steps to reproduce:
- Create a jupyter notebook or jupyter console in HTML mode.
- Define an
xarray.Dataset
containing axarray.DataArray
with non-str
dims:
import xarray
import numpy
xarray.Dataset({
"fsdaf": xarray.DataArray(
numpy.zeros((42, 14, 3)),
dims=(("fsdfsljd", "sdf"), ("fsdaf.w", ), ("fsdaf.c", )),
),
})
- Observe the jupyter cell output: the HTML summary fails to render and falls back to text mode.
...
File <omit>/xarray/core/formatting_html.py:130, in <genexpr>(.0)
128 def summarize_vars(variables) -> str:
129 vars_li = "".join(
--> 130 f"<li class='xr-var-item'>{summarize_variable(k, v)}</li>"
131 for k, v in variables.items()
132 )
134 return f"<ul class='xr-var-list'>{vars_li}</ul>"
File <omit>/xarray/core/formatting_html.py:84, in summarize_variable(name, var, is_index, dtype)
81 variable = var.variable if hasattr(var, "variable") else var
83 cssclass_idx = " class='xr-has-index'" if is_index else ""
---> 84 dims_str = f"({', '.join(escape((dim)) for dim in var.dims)})"
85 name = escape(str(name))
86 dtype = dtype or escape(str(var.dtype))
File <omit>/xarray/core/formatting_html.py:84, in <genexpr>(.0)
81 variable = var.variable if hasattr(var, "variable") else var
83 cssclass_idx = " class='xr-has-index'" if is_index else ""
---> 84 dims_str = f"({', '.join(escape((dim)) for dim in var.dims)})"
85 name = escape(str(name))
86 dtype = dtype or escape(str(var.dtype))
File <omit>/html/__init__.py:19, in escape(s, quote)
12 def escape(s, quote=True):
13 """
14 Replace special characters "&", "<" and ">" to HTML-safe sequences.
15 If the optional flag quote is true (the default), the quotation mark
16 characters, both double quote (") and single quote (') characters are also
17 translated.
18 """
---> 19 s = s.replace("&", "&") # Must be done first!
20 s = s.replace("<", "<")
21 s = s.replace(">", ">")
<xarray.Dataset> Size: 14kB
Dimensions: (('fsdfsljd', 'sdf'): 42, ('fsdaf.w',): 14, ('fsdaf.c',): 3)
Dimensions without coordinates: ('fsdfsljd', 'sdf'), ('fsdaf.w',), ('fsdaf.c',)
Data variables:
fsdaf (('fsdfsljd', 'sdf'), ('fsdaf.w',), ('fsdaf.c',)) float64 14kB 0...
Cause:
The dim names are not converted to str
s first:
https://github.com/pydata/xarray/blob/40119bf35c53fc222934894d842cfc07b2e264bf/xarray/core/formatting_html.py#L84C1-L84C65
thawn
Metadata
Metadata
Assignees
Labels
No labels