add_variables drops non-dimension coordinates since #1078
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 linopy/model.py 中的 _variables_on 开始,追踪 _coords_to_dict 如何处理包含非维度坐标的 xr.Coordinates。使用提供的示例复现,并检查 #1024 的往返测试。当 x.coords 保留 period,且测试明确断言该坐标仍然存在时,即完成。
由索引模型根据 Issue 内容生成。
描述
[!NOTE]
Drafted with AI assistance. The repro was run on both commits below.
Version Checks
- I have confirmed this bug exists on the latest release of Linopy.
- I have confirmed this bug exists on the current
masterbranch of Linopy (b1d6a2e9).
Issue Description
Since #1078, add_variables drops non-dimension coordinates of an xr.Coordinates. The new fast path _variables_on (linopy/model.py:1016) builds its grid with _coords_to_dict, which keeps only dimension coordinates. The coordinates are gone before any constraint or netcdf code runs. This undoes #1024, whose test still passes because both sides of the round trip lack the coordinate.
@FabianHofmann I can open a small fix PR: fall back to the old path in _variables_on when coords carries non-dimension coordinates, and add an assert "time" in x.coords to the #1024 test. OK?
Reproducible Example
import numpy as np, xarray as xr, linopy
coords = xr.Coordinates({"snapshot": np.arange(4), "period": ("snapshot", [2020, 2020, 2030, 2030])})
x = linopy.Model().add_variables(lower=0, coords=coords, name="x")
print(list(x.coords))
# b1d6a2e9 (#1078): ['snapshot']
# 81891602 (before): ['snapshot', 'period']
Expected Behavior
x.coords keeps period, as before #1078.
Installed Versions
linopy master b1d6a2e9, Python 3.12.
- 主要语言
- Python
- 星标
- 263
- 派生
- 92
- 平均合并
- 1 天 13 小时
- 30 天内合并 PR
- 32
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PyPSA/linopy 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Constant LinearExpression * multi-term LinearExpression raises TypeError (mirrored product works)可能已有人在做 @anveshachuri 于 2 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug solver interface
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
相似的 Issue
-
enhancement help wanted
难度 2/5 1-3 小时 新手友好度 76/100
Git-Hospital/githealthcheck#61 ·
维护者通常 1 天内回复
-
changelog investigate
难度 2/5 1-3 小时 新手友好度 67/100
ramnes/notion-sdk-py#433 ·
-
Partial method descriptors raise on class access可能已有人在做 @Gambit-Checkmate 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 19 天内回复
-
docs pkg:core
难度 1/5 1 小时以内 新手友好度 84/100
pydantic/pydantic-ai#11929 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
intake/intake-esm#789 ·