diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 646e000a98..38dccfa203 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -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): diff --git a/xarray/tests/test_namedarray.py b/xarray/tests/test_namedarray.py index 5e4a39ada7..39ca08fa06 100644 --- a/xarray/tests/test_namedarray.py +++ b/xarray/tests/test_namedarray.py @@ -591,3 +591,15 @@ 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[Any, np.dtype[np.uint64]] + x = NamedArray(("x",), np.array([0], dtype=np.uint64)) + + # Reprs should not crash: + r = x.__repr__() + x._repr_html_() + + # Basic comparison: + assert r == " Size: 8B\narray([0], dtype=uint64)"