Skip to content

Commit a64cf2d

Browse files
authored
Show data by default in HTML repr for DataArray (#4182)
* Show data by default in HTML repr for DataArray Fixes GH-4176 * add whats new for html repr * fix test
1 parent 732750a commit a64cf2d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ Breaking changes
3939
the default behaviour of :py:func:`open_mfdataset` has changed to use
4040
``combine='by_coords'`` as the default argument value. (:issue:`2616`, :pull:`3926`)
4141
By `Tom Nicholas <https://github.com/TomNicholas>`_.
42-
42+
- The ``DataArray`` and ``Variable`` HTML reprs now expand the data section by
43+
default (:issue:`4176`)
44+
By `Stephan Hoyer <https://github.com/shoyer>`_.
4345

4446
Enhancements
4547
~~~~~~~~~~~~

xarray/core/formatting_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def dim_section(obj):
184184
def array_section(obj):
185185
# "unique" id to expand/collapse the section
186186
data_id = "section-" + str(uuid.uuid4())
187-
collapsed = ""
187+
collapsed = "checked"
188188
variable = getattr(obj, "variable", obj)
189189
preview = escape(inline_variable_array_repr(variable, max_width=70))
190190
data_repr = short_data_repr_html(obj)

xarray/tests/test_formatting_html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def test_summarize_attrs_with_unsafe_attr_name_and_value():
108108
def test_repr_of_dataarray(dataarray):
109109
formatted = fh.array_repr(dataarray)
110110
assert "dim_0" in formatted
111-
# has an expandable data section
112-
assert formatted.count("class='xr-array-in' type='checkbox' >") == 1
111+
# has an expanded data section
112+
assert formatted.count("class='xr-array-in' type='checkbox' checked>") == 1
113113
# coords and attrs don't have an items so they'll be be disabled and collapsed
114114
assert (
115115
formatted.count("class='xr-section-summary-in' type='checkbox' disabled >") == 2

0 commit comments

Comments
 (0)