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

add_variables drops non-dimension coordinates since #1078

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

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

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

評価

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

調査の方向性

linopy/model.py の _variables_on から始め、_coords_to_dict が次元ではない座標を持つ xr.Coordinates をどのように扱うかを追ってください。提示された例で再現し、#1024 の round-trip テストを調べてください。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 master branch 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時間
マージ済み PR(30日)
32

環境構築

はじめの一歩

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

PyPSA/linopy のほかの issue

PyPSA/linopy の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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