diff --git a/src/async_geotiff/_array.py b/src/async_geotiff/_array.py index cd88e0a..cf30c89 100644 --- a/src/async_geotiff/_array.py +++ b/src/async_geotiff/_array.py @@ -52,6 +52,14 @@ class RasterArray(TransformMixin): _geotiff: GeoTIFF """A reference to the parent GeoTIFF.""" + def __repr__(self) -> str: + """Summarize metadata without formatting pixel or mask values.""" + return ( + f"async_geotiff.RasterArray(shape={self.shape}, " + f"dtype={str(self.data.dtype)!r}, " + f"has_mask={self.mask is not None})" + ) + @classmethod def _create( # noqa: PLR0913 cls, diff --git a/tests/test_array.py b/tests/test_array.py new file mode 100644 index 0000000..65d1272 --- /dev/null +++ b/tests/test_array.py @@ -0,0 +1,50 @@ +"""Tests for raster array metadata.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +import numpy as np +import pytest + +from async_geotiff import Window + +if TYPE_CHECKING: + from .conftest import LoadGeoTIFF + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("name", "expected"), + [ + ( + "uint8_rgb_deflate_block64_cog", + "async_geotiff.RasterArray(shape=(3, 3, 4), dtype='uint8', has_mask=False)", + ), + ( + "cog_uint8_rgb_mask", + "async_geotiff.RasterArray(shape=(3, 3, 4), dtype='uint8', has_mask=True)", + ), + ( + "float32_1band_lerc_block32", + ( + "async_geotiff.RasterArray(shape=(1, 3, 4), dtype='float32', " + "has_mask=False)" + ), + ), + ], +) +async def test_repr_summarizes_array_metadata( + load_geotiff: LoadGeoTIFF, + name: str, + expected: str, +) -> None: + image = await load_geotiff(name) + array = await image.read( + window=Window(col_off=0, row_off=0, width=4, height=3), + ) + + # Array contents and private parent objects must not enter the summary, + # even when NumPy is configured to print every value. + with np.printoptions(threshold=np.inf): + assert repr(array) == expected