Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

add_variables drops non-dimension coordinates since #1078

Đang mở Phù hợp với người mới
#1,084 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu tại linopy/model.py, ở _variables_on, rồi theo dõi cách _coords_to_dict xử lý xr.Coordinates có các tọa độ không phải là chiều. Tái hiện bằng ví dụ được cung cấp và kiểm tra bài kiểm thử round-trip #1024. Hoàn tất khi x.coords giữ lại period và bài kiểm thử khẳng định rõ rằng tọa độ đó được giữ lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

[!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.

Ngôn ngữ chính
Python
Star
263
Fork
92
Merge trung bình
1 ngày 13 giờ
Pull request đã merge (30 ngày)
32

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PyPSA/linopy

Tất cả issue của PyPSA/linopy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.