Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

to_dataset keeps the last row per dim tuple instead of raising on duplicates

未关闭
#247 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start at to_dataset in the result class and read its docstring's Raises section, which promises a ValueError on duplicate dim tuples. Run the repro in the issue (3 time steps, lat/lon grid, SELECT without time) to confirm 12 rows collapse to 4. Done when that case raises ValueError naming the duplicate dims, and a test covers it. The issue leaves open whether the check should always run or only when dims were inferred, so confirm that with maintainers first.

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

描述

When a query projects a dimension away, the rows that dimension separated collapse onto the same dim tuple. to_dataset builds a grid from them anyway, keeping whichever row comes last, and returns it without a warning. The docstring says it raises instead:

Raises:
    ValueError: ``dims`` cannot be inferred, names a missing
        column, or the result has duplicate dim tuples;

Repro on 0.3.3 and 0.4.0rc1:

import numpy as np
import pandas as pd
import xarray as xr

from xarray_sql import XarrayContext

temp = np.arange(12.0).reshape(3, 2, 2)
ds = xr.Dataset(
    {"temperature": (["time", "lat", "lon"], temp)},
    coords={
        "time": pd.date_range("2020-01-01", periods=3),
        "lat": [10.0, 20.0],
        "lon": [100.0, 110.0],
    },
)

ctx = XarrayContext()
ctx.from_dataset("temperature", ds, chunks={"time": 3, "lat": 2, "lon": 2})
result = ctx.sql("SELECT lat, lon, temperature FROM temperature")

print(len(result.to_pandas()))  # 12 rows, 4 unique (lat, lon)
print(result.to_dataset(dims=["lat", "lon"])["temperature"].values)
12
[[ 8.  9.]
 [10. 11.]]

That is temp[-1], the last time step. Two thirds of the input is gone and nothing says so. Inferring the dims (dims=None) gives the same result.

The value is also arbitrary rather than merely lossy: it depends on the order rows happen to arrive in, so the same query can return different numbers across partitionings.

Raising the documented ValueError seems right to me, since the alternative is picking an aggregation the caller did not ask for. Detecting it costs a scan, so making it conditional (or checking only when dims was inferred) may be worth it.

I hit this from Lumen, where a projecting SQL transform drops a dim before the source grids the result. Happy to send a PR if you want it fixed this way.

主要语言
Python
星标
142
派生
19
平均合并
1 天 9 小时
30 天内合并 PR
9

环境准备

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

从这里开始

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

xqlsystems/xarray-sql 的其他 Issue

查看 xqlsystems/xarray-sql 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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