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

未关闭
#16,504 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@omkhpb25 已经在做这个了。

开始于 2026年10月21日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
numpy, python
领域
tooling

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Python
星标
5.1k
派生
2.1k
平均合并
2 天 7 分钟
30 天内合并 PR
116

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python/typeshed 的其他 Issue

查看 python/typeshed 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。