Check attribute content against netCDF's constraints before saving
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Read the netCDF saver and lib/iris/fileformats/netcdf/_attribute_handlers.py to locate where cube attributes are passed to setncattr; the issue does not name the saver file or a test. Check the existing tests for netCDF attribute saving, then add coverage for unsupported multidimensional values and errors that identify the attribute and variable. Done means invalid content fails before writing with a clear error, while valid attributes still save.
索引モデルが issue の本文から書いたものです。
説明
(posted by Claude Opus)
Raised from @pp-mo's review of the Zarr I/O design spec: https://github.com/SciTools/iris/pull/7292#discussion_r4155016083
The problem
netCDF constrains what an attribute may hold: a scalar, a string, or a one-dimensional array. Iris does not check this before saving. A cube carrying, say, a 2-D array attribute reaches setncattr and fails inside netCDF4 with a message that names neither the attribute nor the cube.
@pp-mo:
For netCDF4 specifically, possible attribute content is further constrained (e.g. only 1-D arrays). We should make explicit checks and raise errors or warnings when saving unsupported content.
What to do
Check before writing, and raise an error naming the attribute, the variable and why the content cannot be stored.
Raise, do not warn-and-stringify. The same review suggested generalising the known-object handlers in lib/iris/fileformats/netcdf/_attribute_handlers.py — STASH codes, cell methods — into "convert anything unrecognised to its string form and emit a warning". @trexfeathers declined that, and the reasoning is worth keeping with the issue:
I confidently see
_attribute_handlersas a special case for things where there is an obvious and understood way to represent something as a string. This does not generalise to everything that might not be storable in the file (e.g. someone assigns an object which has a__str__and__repr__, but neither of which is adequate for reconstructing said object downstream; that would be a very different decision we are making). In Iris we are typically very careful about Cube-to-Cube roundtripping - can I save a Cube to a file then load back a Cube that is the same as the original - and falling back on converting all unsaveable content to a string seems to deviate from that.
The existing handlers convert where the string form is defined and reversible, and implement the reverse direction beside it. str(some_object) has neither property. A warning is also the wrong instrument here: it does not stop the save, so the user gets a file, is told in passing that part of it is now prose, and finds out at load time.
Scope
This is a behaviour change to the netCDF saver, so it is out of scope for the Zarr I/O programme (#6961) — PR 5 of that programme relocates this code without changing it. The Zarr write path already raises for a value it cannot represent, which is the same policy.
- 主要言語
- Python
- スター
- 730
- フォーク
- 323
- 平均マージ
- 3日 21時間
- マージ済み PR(30日)
- 16
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SciTools/iris のほかの issue
-
Link Checker Report対応中かも @stephenworsley が 12 日前に担当しました。 オープンBot Type: Bug Type: Documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
SciTools/iris#7368 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
guess_bounds(yearly=True) fails on a single point, monthly=True works対応中かも @pp-mo が 47 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
SciTools/iris#7311 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Agentic
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
jxxghp/MoviePilot#7576 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
jbaruch/software-factory#266 ·
メンテナーはふだん 1 日以内に返信
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信