Skip to content

[rasterio] numpy arrays in transform.xy, a crs of None, and read(masked=True) #16504

Description

@bjlittle

Researched and drafted by Claude (Anthropic's AI model, in Claude Code), which also ran the measurements below; reviewed by @bjlittle before posting.

Type checking geovista against types-rasterio 1.5.2.20261005 turned up three places where the rasterio stubs are narrower than rasterio 1.5.2 at runtime.

  1. rasterio.transform.xy types rows and cols as int | Sequence[int], and its result as tuple[float, float] | tuple[list[float], list[float]]. rasterio takes numpy arrays, and gives arrays back for them:

    import numpy as np
    from rasterio.transform import from_origin, xy
    
    transform = from_origin(10.0, 20.0, 1.0, 1.0)
    rows, cols = np.meshgrid(np.arange(2), np.arange(3), indexing="ij")
    xs, ys = xy(transform, rows.flatten(), cols.flatten())
    type(xs)  # <class 'numpy.ndarray'>

    An ndarray is not a Sequence, so a caller passing one needs a cast.

  2. DatasetBase.crs is typed CRS, but a GeoTIFF without a CRS gives None.

  3. DatasetReaderBase.read is typed to return NDArray[Any] whatever masked is, but with masked=True it returns a numpy.ma.MaskedArray, so using its mask doesn't type check.

If any of these would be welcome as a pull request, Claude can prepare one the same way, for @bjlittle to review before it is opened.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions