Model result and observation constructors stamp `kind` into the Dataset they are handed
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Start with TimeSeries.init and _validate_dataset in src/modelskill/timeseries/_timeseries.py, then inspect the five constructor sites listed in the issue and the existing vertical re-wrapping tests. Run tests/observation/test_vertical_obs.py and tests/model/test_vertical.py before adding coverage for a source observation surviving a model-result read. Done means constructors no longer mutate handed-in datasets while existing behavior remains intact.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
TimeSeries.__init__ (src/modelskill/timeseries/_timeseries.py:171) keeps the dataset it is given, by reference:
self.data = data if self._is_input_validated(data) else _validate_dataset(data)
Each constructor then marks the primary variable's kind in place. On the validated path that variable belongs to the caller, so reading an observation's data turns the observation into a model result:
o = ms.PointObservation(df, x=1.0, y=2.0, item="WL")
o.data["WL"].attrs["kind"] # 'observation'
mr = ms.PointModelResult(o.data)
o.data["WL"].attrs["kind"] # 'model' <- the observation changed
mr.data is o.data # True
Sites
The same three lines are copy-pasted at five constructors:
src/modelskill/model/point.py:69src/modelskill/model/track.py:71src/modelskill/model/vertical.py:113src/modelskill/obs.py:155src/modelskill/model/network.py— fixed onnetwork-phase-2by copying first
Observation.__init__ (src/modelskill/obs.py:152-165) goes furthest. Beyond kind it rewrites the source's dataset-level attrs, its time variable, the plot color and weight:
data.attrs = {**data.attrs, **(attrs or {})}
data["time"] = self._parse_time(data.time)
data[data_var].attrs["color"] = color
super().__init__(data=data)
self.data.attrs["weight"] = weight
_validate_dataset (_timeseries.py:117-160) also mutates its argument and returns it, so the unvalidated path is only incidentally safe: it is safe because the parse functions built a fresh object, not because anything copied.
Why it has gone unnoticed
Re-wrapping a validated dataset is rare, and the two tests that do it re-wrap same-to-same, where the kind written matches the kind already there: tests/observation/test_vertical_obs.py:184 and tests/model/test_vertical.py:170. Nothing asserts that a source observation survives being read.
DummyModelResult is the one class already safe, and it is safe because it copies — da = observation.data[observation.name].copy() (src/modelskill/model/dummy.py:65).
comparison/_comparison.py:509 is a latent instance: PointModelResult(self.data[[str(key)]], name=str(key)) stamps a variable still shared with Comparer.data, because ds[[var]] shares Variable objects. It is benign only because the kind already reads model.
Suggested fix
A shallow ds.copy() before stamping is enough — xarray rebuilds each variable's attrs dict, so no array data is copied. deep=True is not needed. Note that ds[[var]], ds.sel(...) and ds.isel(...) do not work for this: they share the Variable objects and the write goes through to the parent.
Since the stamp is duplicated five times, one helper that copies and then marks the primary variable would remove the duplication and the aliasing together. _include_attributes and _include_coords (timeseries/_point.py:150, :168) already open with ds = ds.copy(), so the discipline exists in the codebase.
- Ngôn ngữ chính
- Python
- Star
- 58
- Fork
- 10
- Merge trung bình
- 1 giờ 16 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DHI/modelskill
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DHI/modelskill#732 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DHI/modelskill#731 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
DHI/modelskill#728 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
NSE and R2 return 1.0 when model values are NaNCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DHI/modelskill#720 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
DHI/modelskill#628 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của DHI/modelskill
Issue tương tự
-
Admin member of a research group cannot see the HX2 allocation until they've been added to itĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
developmentseed/titiler-cmr#278 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 2 ngày