Check attribute content against netCDF's constraints before saving
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 66/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
(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.
- Lingua principale
- Python
- Stelle
- 730
- Fork
- 323
- Merge medio
- 3g 21h
- PR unite (30g)
- 16
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di SciTools/iris
-
Link Checker ReportForse già presa @stephenworsley l’ha presa 12 giorni fa. ApertaBot Type: Bug Type: Documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
SciTools/iris#7368 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
guess_bounds(yearly=True) fails on a single point, monthly=True worksForse già presa @pp-mo l’ha presa 47 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
SciTools/iris#7311 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Agentic
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di SciTools/iris
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
UKGovernmentBEIS/inspect_ai#6733 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ProyectoRespira/respira-webapp#334 ·
I maintainer di solito rispondono entro 1 giorno
-
bug security-alert
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
spectrayan/carefold#391 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
Jakeschincariol/instagram-agent-skill#83 ·
I maintainer di solito rispondono entro 10 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 64/100