Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/async_geotiff/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
50 changes: 50 additions & 0 deletions tests/test_array.py
Original file line number Diff line number Diff line change
@@ -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
Loading