Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NamedArray html repr crashing #9553

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def inline_variable_array_repr(var, max_width):
"""Build a one-line summary of a variable's data."""
if hasattr(var._data, "_repr_inline_"):
return var._data._repr_inline_(max_width)
if var._in_memory:
if getattr(var, "_in_memory", False):
return format_array_flat(var, max_width)
dask_array_type = array_type("dask")
if isinstance(var._data, dask_array_type):
Expand Down
11 changes: 11 additions & 0 deletions xarray/tests/test_namedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,14 @@ def test_broadcast_to_errors(
def test_warn_on_repeated_dimension_names(self) -> None:
with pytest.warns(UserWarning, match="Duplicate dimension names"):
NamedArray(("x", "x"), np.arange(4).reshape(2, 2))


def test_repr() -> None:
x = NamedArray(("x",), np.array([1, 2, 3]))

# Reprs should not crash:
r = x.__repr__()
x._repr_html_()

# Basic comparison:
assert r == "<xarray.NamedArray (x: 3)> Size: 24B\narray([1, 2, 3])"
Loading