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

Ouverte
#16,504 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@omkhpb25 y travaille déjà.

Depuis le 21/10/2026.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
numpy, python
Domaine
tooling

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
Python
Étoiles
5.1k
Forks
2.1k
Merge moyen
2 j 7 min
PR mergées (30 j)
116

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python/typeshed

Toutes les issues de python/typeshed

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.