Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

polygon_query on points resets the index and rewrites the coordinate systems (adds a bogus `global: Identity`)

オープン
#1,211 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
pandas, python
領域
data

調査の方向性

src/spatialdata/_core/query/spatial_query.py の DaskDataFrame オーバーロードである polygon_query と、src/spatialdata/models/_utils.py の points_dask_dataframe_to_geopandas から始めます。まず、提供されている repro.py を実行してください。polygon_query と bounding_box_query を比較し、クエリされたポイントがインデックス [100, 200] と座標系 ['aligned', 'other'] を保持し、'global' を追加しないことを確認してください。

索引モデルが issue の本文から書いたものです。

説明

bug 🚨 element: points ⊙ method: query needs: triage priority: high

[!NOTE]
This whole message is AI-generated. The issue was automatically discovered and reported by an AI agent (Claude) during an autonomous bug hunt on the spatialdata code base. It has not been verified or triaged by a human yet; the needs: triage label is set so that a maintainer can confirm it. The reproduction script below was executed by the agent in an isolated environment (see Environment) and its output is pasted verbatim.

Summary

The dask → geopandas → dask round trip used by polygon_query calls reset_index(drop=True) and loses .attrs, so PointsModel.parse installs the default {"global": Identity()} and only the queried coordinate system is set on top. For points with index [100, 200, 300] and transformations {"aligned": Scale, "other": Identity} (no global), the result has index [0, 1] and transformations {"global": Identity, "aligned": Scale}: the original ids are gone, other is dropped and an invented mapping to global is added. bounding_box_query on the same element behaves correctly.

Severity (agent's assessment): high — point ids are lost and the returned element is mis-positioned in global

Where: src/spatialdata/_core/query/spatial_query.py, DaskDataFrame overload of polygon_query; src/spatialdata/models/_utils.py::points_dask_dataframe_to_geopandas (reset_index(drop=True))

Expected behaviour

Same behaviour as bounding_box_query: original index and all coordinate systems preserved, no global added.

Reproduction

Save as repro.py and run uv run repro.py (the PEP 723 header pins spatialdata to the commit the bug was found on; replace the URL fragment with @main to test the current main branch).

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "spatialdata @ git+https://github.com/scverse/spatialdata.git@ccf1ea048d054b6624214bf618008a9f9ae223e0",
# ]
# ///
"""polygon_query on points resets the index and rewrites the coordinate systems (adds a bogus global Identity)."""
import warnings
import pandas as pd
from shapely.geometry import box
from spatialdata import bounding_box_query, polygon_query
from spatialdata.models import PointsModel
from spatialdata.transformations import Identity, Scale, get_transformation

warnings.simplefilter("ignore")
df = pd.DataFrame({"x": [1.0, 5.0, 9.0], "y": [1.0, 5.0, 9.0], "gene": pd.Categorical(["a", "b", "c"])}, index=[100, 200, 300])
points = PointsModel.parse(df, feature_key="gene", transformations={"aligned": Scale([2.0, 2.0], axes=("x", "y")), "other": Identity()})
print("original index:", df.index.tolist(), "| original coordinate systems:", sorted(get_transformation(points, get_all=True)))
poly = polygon_query(points, polygon=box(0, 0, 12, 12), target_coordinate_system="aligned")
bbox = bounding_box_query(points, axes=("x", "y"), min_coordinate=[0, 0], max_coordinate=[12, 12], target_coordinate_system="aligned")
print("polygon_query      -> index:", poly.index.compute().tolist(), "| coordinate systems:", {k: type(v).__name__ for k, v in get_transformation(poly, get_all=True).items()})
print("bounding_box_query -> index:", bbox.index.compute().tolist(), "| coordinate systems:", sorted(get_transformation(bbox, get_all=True)))
print("expected for both: index [100, 200] and coordinate systems ['aligned', 'other'] (no 'global')")
bug = poly.index.compute().tolist() != [100, 200] or "global" in get_transformation(poly, get_all=True) or "other" not in get_transformation(poly, get_all=True)
print("VERDICT:", "BUG REPRODUCED" if bug else "NOT REPRODUCED")
Observed output
original index: [100, 200, 300] | original coordinate systems: ['aligned', 'other']
polygon_query      -> index: [0, 1] | coordinate systems: {'global': 'Identity', 'aligned': 'Scale'}
bounding_box_query -> index: [100, 200] | coordinate systems: ['aligned', 'other']
expected for both: index [100, 200] and coordinate systems ['aligned', 'other'] (no 'global')
VERDICT: BUG REPRODUCED

Possible fix direction (unverified)

Filter the computed pandas frame directly (as bounding_box_query does) and re-parse with transformations=get_transformation(points, get_all=True).copy(); or make points_dask_dataframe_to_geopandas keep the index and attrs.

Environment

uv run repro.py with the PEP 723 metadata in the script (fresh, isolated environment; spatialdata built from main @ ccf1ea0 (2026-08-28); Python 3.13, latest releases of the dependencies at run time: pandas 3.0, anndata 0.13, zarr 3.3, dask 2026.8, numpy 2.5, geopandas 1.1, shapely 2.1). macOS (arm64). Also reproduced in a second environment with pandas 2.3.3 / anndata 0.12.11 / numpy 2.4.4 / zarr 3.2.1.


Automatically generated; discovered by an AI agent (Claude) and not yet reviewed by a human.

主要言語
Python
スター
397
フォーク
98
平均マージ
5日 9時間
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

scverse/spatialdata のほかの issue

scverse/spatialdata の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。