Repository navigation
Add optional reference (production) exchange column to datapackage schema - #108
Merged
Merged
Conversation
…hema Adds an optional per-exchange `reference` boolean column, stored as its own side-resource (`kind="reference"`) exactly like `flip`/`rescale`: additive, backward compatible, and written only when at least one entry is flagged. Modellers can now record which technosphere exchange is the reference (production) exchange, so consumers such as bw_graph_tools can read it directly instead of relying on structural heuristics, which cannot disambiguate co-production columns (an activity with multiple same-sign outputs whose products also appear in other columns). - MatrixEntry.reference / ArrayEntry.reference - reference_array kwarg on all add_* methods + _add_reference_array_resource - threaded through dictionary_formatter / resolve_dict_iterator - "reference" added to Parquet kind mapping and merging suffix whitelist - README section, CHANGES entry, version bump 1.5 -> 1.6 - tests: dataclass defaults/validation, low-level validation, skip-when-empty, write->reload round-trip Refs cauldron/brightway-api#739
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.
Summary
Adds an optional per-exchange
referenceboolean column to the datapackage schema, stored as its own side-resource (kind="reference") exactly likeflip/rescale: additive, backward compatible, and written only when at least one entry is flagged.Modellers can now record which technosphere exchange is the reference (production) exchange for an activity, so consumers such as
bw_graph_toolscan read it directly instead of relying on structural heuristics. Those heuristics cannot disambiguate co-production columns — an activity with more than one same-sign exchange whose products also appear in other columns (e.g. process A co-produces product Y and waste Z, process B treats Z while consuming Y). In that case no sign/flip/uniqueness rule can recover the modeller's intent, andguess_production_exchangesraisesUnclearProductionExchange. See cauldron/brightway-api#739 for the full problem write-up.Design
A separate optional resource rather than a new field in
INDICES_DTYPE, because the indices dtype is format-pinned (strictly asserted in the Parquet path, hand-built field-by-field) and mandatory/universal; a separate resource is non-breaking and zero-cost when unused.Changes
MatrixEntry.reference: bool = False;ArrayEntry.reference: Optional[np.ndarray](bool coercion + shape validation).reference_arraykwarg onadd_persistent_vector,add_persistent_array,add_dynamic_vector,add_dynamic_array; threaded fromadd_entries/add_array_entries; new_add_reference_array_resourcehelper.dictionary_formatter/resolve_dict_iterator."reference"added to the Parquetkindmapping and to the merging resource-suffix whitelist (also adds the previously-missingrescalethere).CHANGES.mdentry, version bump 1.5 → 1.6.Tests
Dataclass defaults/validation, formatter/resolver, low-level validation (wrong dtype, shape mismatch), skip-when-empty, and a write→reload round-trip. Full suite: 273 passed, 1 skipped.
Follow-ups (separate PRs, not in this change)
matrix_utils: exposehas_reference/referenceonResourceGroup.bw_graph_tools: an authoritative "heuristic zero" that readsgroup.referencefirst inguess_production_exchanges.Refs cauldron/brightway-api#739