@@ -575,17 +575,28 @@ def test_large_array_repr_length() -> None:
575
575
576
576
@requires_netCDF4
577
577
def test_repr_file_collapsed (tmp_path ) -> None :
578
- arr = xr .DataArray (np .arange (300 ), dims = "test" )
579
- arr .to_netcdf (tmp_path / "test.nc" , engine = "netcdf4" )
578
+ arr_to_store = xr .DataArray (np .arange (300 , dtype = np . int64 ), dims = "test" )
579
+ arr_to_store .to_netcdf (tmp_path / "test.nc" , engine = "netcdf4" )
580
580
581
581
with xr .open_dataarray (tmp_path / "test.nc" ) as arr , xr .set_options (
582
582
display_expand_data = False
583
583
):
584
- actual = formatting . array_repr (arr )
584
+ actual = repr (arr )
585
585
expected = dedent (
586
586
"""\
587
587
<xarray.DataArray (test: 300)>
588
- array([ 0, 1, 2, ..., 297, 298, 299])
588
+ [300 values with dtype=int64]
589
+ Dimensions without coordinates: test"""
590
+ )
591
+
592
+ assert actual == expected
593
+
594
+ arr_loaded = arr .compute ()
595
+ actual = arr_loaded .__repr__ ()
596
+ expected = dedent (
597
+ """\
598
+ <xarray.DataArray (test: 300)>
599
+ 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 288 289 290 291 292 293 294 295 296 297 298 299
589
600
Dimensions without coordinates: test"""
590
601
)
591
602
@@ -699,3 +710,18 @@ def test__element_formatter(n_elements: int = 100) -> None:
699
710
)
700
711
actual = intro + values
701
712
assert expected == actual
713
+
714
+
715
+ def test_lazy_array_wont_compute () -> None :
716
+ from xarray .core .indexing import LazilyIndexedArray
717
+
718
+ class LazilyIndexedArrayNotComputable (LazilyIndexedArray ):
719
+ def __array__ (self , dtype = None ):
720
+ raise NotImplementedError ("Computing this array is not possible." )
721
+
722
+ arr = LazilyIndexedArrayNotComputable (np .array ([1 , 2 ]))
723
+ var = xr .DataArray (arr )
724
+
725
+ # These will crash if var.data are converted to numpy arrays:
726
+ var .__repr__ ()
727
+ var ._repr_html_ ()
0 commit comments