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

Aperta
#16,504 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@omkhpb25 ci sta già lavorando.

Dal 21/10/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, python
Ambito
tooling

Direzione di ricerca

The three problems are in the rasterio stubs bundled in typeshed: rasterio.transform.xy (the rows/cols parameters and return type), DatasetBase.crs, and DatasetReaderBase.read (the return type when masked=True). Reproduce each case with the snippets in the issue, then compare against the current stub signatures. Done means the stubs accept numpy arrays, allow crs to be None, and return a masked array type when masked=True, with the repository's stub tests passing. The issue asks for maintainer approval before a pull request, so confirm that first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
5.1k
Fork
2.1k
Merge medio
2g 1h
PR unite (30g)
115

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/typeshed

Tutte le issue di python/typeshed

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.