Treat any extra site key or column as a label, not just a name - #8
Closed
lispandfound wants to merge 1 commit into
Closed
lispandfound wants to merge 1 commit into
lispandfound wants to merge 1 commit into
Conversation
`site` was a privileged coordinate: `Site` declared a required `name`, the
builder wrote it to a fixed `Coordinate.SITE`, and a station's network code or
a driller's reference had nowhere to go. Nothing about a borehole grid earns
that. The grid needs a position; everything else is the caller's business.
Longitude and latitude now place a site and the config reserves nothing else.
Every other key in a `[[grid.sites]]` block, and every other column of a CSV
or Parquet site file, becomes a coordinate on the `i` axis under the name the
caller gave it, and so a column in table output. A label keeps the type it was
written with, so a numeric column arrives numeric. `Coordinate.SITE` is gone;
`examples/borehole.toml` calls its labels `site` and `network`, and the code
privileges neither.
Two things the change has to guard.
A coordinate shadows a variable or attribute of the same name, so a label
called `name` would turn `grid.name` from the grid's name into a DataArray and
break `{grid.name: grid}`. `RESERVED_COORDINATES` in `nzcvm.grids.grid` is
derived from `GridSchema`'s own fields, plus the logical index, the coastline
coordinate and the component names a writer merges alongside the grid, so it
keeps up if the schema changes. A label naming one of those raises.
Sites also have to agree on which labels they carry. A missing key is nearly
always a typo, and the alternative is a column of nulls.
`keep_extra_columns = false` drops the labels and keeps only the spatial
coordinates.
Mashumaro folds the extra keys in a `__pre_deserialize__` hook, so the
longitude and latitude validators still run and a config file needn't spell
the `labels` mapping out.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
lispandfound
added this pull request to stack #6
September 10, 2026 10:19
Benchmark for 8868c0fClick to view benchmark
|
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sitewas a privileged coordinate.Sitedeclared a requiredname, thebuilder wrote it to a fixed
Coordinate.SITE, and a station's network code ora driller's reference had nowhere to go. Nothing about a borehole grid earns
that: the grid needs a position, and everything else is the caller's business.
Longitude and latitude place a site; nothing else is reserved
Every other key in a
[[grid.sites]]block, and every other column of a CSVor Parquet site file, becomes a coordinate on the
iaxis under the name thecaller gave it, and so a column in table output.
A label keeps the type it was written with, so a numeric column arrives
numeric rather than stringified.
Coordinate.SITEis gone, andexamples/borehole.tomlcalls its labelssiteandnetworkwhile the codeprivileges neither.
Mashumaro folds the extra keys in a
__pre_deserialize__hook, so thelongitude and latitude validators still run and a config file needn't spell
the
labelsmapping out.keep_extra_columns = falsedrops the labels and keeps only the spatialcoordinates.
Two things this has to guard
A label can't shadow a grid name. A coordinate shadows a variable or
attribute of the same name, so a label called
namewould turngrid.namefrom the grid's name into a
DataArrayand break{grid.name: grid}in thebuilder. I confirmed that before relying on it:
RESERVED_COORDINATESinnzcvm.grids.gridis derived fromGridSchema'sown fields, plus the logical index, the coastline coordinate and the component
names a writer merges alongside the grid, so it keeps up if the schema
changes. A label naming one of those raises:
Sites have to agree on their labels. A missing key is nearly always a
typo, and the alternative is a column of nulls:
keep_extra_columns = falseskips both checks, since there is nothing left tocollide or disagree.
Testing
All three writers carry both labels through: CSV and Parquet as
siteandnetworkcolumns, Zarr as coordinates oni. Verified for inline TOML keys,CSV columns and Parquet columns (including a numeric label that stays
float64), forkeep_extra_columns = false, and for both error paths.Incidental finding, not fixed here
ConfigObjectsetsforbid_extra_keys = Trueon a nested class namedMeta,but mashumaro looks for one named
Config, so the setting is inert acrossevery config in the package — an unknown key anywhere is silently dropped
rather than reported:
That is why extra site keys could be accepted before this change; they just
went nowhere. Renaming
MetatoConfigwould start rejecting typos in everyconfig section, which is a good change but a wider one than this PR, so I left
it alone.
Co-Authored-By: Claude Opus 5 noreply@anthropic.com
Stack created with GitHub Stacks CLI • Give Feedback 💬