Skip to content

Commit

Permalink
Show data by default in HTML repr for DataArray (#4182)
Browse files Browse the repository at this point in the history
* Show data by default in HTML repr for DataArray

Fixes GH-4176

* add whats new for html repr

* fix test
  • Loading branch information
shoyer authored Jun 28, 2020
1 parent 732750a commit a64cf2d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Breaking changes
the default behaviour of :py:func:`open_mfdataset` has changed to use
``combine='by_coords'`` as the default argument value. (:issue:`2616`, :pull:`3926`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.

- The ``DataArray`` and ``Variable`` HTML reprs now expand the data section by
default (:issue:`4176`)
By `Stephan Hoyer <https://github.com/shoyer>`_.

Enhancements
~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def dim_section(obj):
def array_section(obj):
# "unique" id to expand/collapse the section
data_id = "section-" + str(uuid.uuid4())
collapsed = ""
collapsed = "checked"
variable = getattr(obj, "variable", obj)
preview = escape(inline_variable_array_repr(variable, max_width=70))
data_repr = short_data_repr_html(obj)
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def test_summarize_attrs_with_unsafe_attr_name_and_value():
def test_repr_of_dataarray(dataarray):
formatted = fh.array_repr(dataarray)
assert "dim_0" in formatted
# has an expandable data section
assert formatted.count("class='xr-array-in' type='checkbox' >") == 1
# has an expanded data section
assert formatted.count("class='xr-array-in' type='checkbox' checked>") == 1
# coords and attrs don't have an items so they'll be be disabled and collapsed
assert (
formatted.count("class='xr-section-summary-in' type='checkbox' disabled >") == 2
Expand Down

0 comments on commit a64cf2d

Please sign in to comment.