Skip to content

Generalize types to create NetworkModelResults#589

Draft
jpalm3r wants to merge 31 commits intojapr/network-supportfrom
japr/network-protocol
Draft

Generalize types to create NetworkModelResults#589
jpalm3r wants to merge 31 commits intojapr/network-supportfrom
japr/network-protocol

Conversation

@jpalm3r
Copy link
Collaborator

@jpalm3r jpalm3r commented Feb 23, 2026

This pull request improves the flexibility and robustness of the network model input handling by allowing both pandas.DataFrame and xarray.Dataset types as input to NetworkModelResult, and by adding thorough validation and conversion logic. The changes primarily focus on input validation, error messaging, and making the codebase more extensible for future enhancements.

Key changes:

Input validation and conversion:

  • Added a new _to_network_dataset function in network.py that validates and converts inputs of type NetworkType (either pd.DataFrame or xr.Dataset) to an xr.Dataset, with detailed type and structure checks for DataFrame inputs. This function raises clear errors for invalid input types or structures.

Constructor enhancements:

  • Updated the NetworkModelResult constructor to accept a NetworkType (instead of only xr.Dataset), using the new _to_network_dataset function to ensure the input is properly validated and converted before further processing.

Notebook demonstration:

  • Added a new code cell in Collection_systems_network.ipynb to display the node values from the network model, likely as part of demonstrating or testing the improved input handling.

- Updated NodeObservation class to allow creation of multiple observations by passing lists for node and item parameters.
- Implemented auto-assignment of item indices when only nodes are provided and their count matches the number of data columns.
- Added validation to ensure that the lengths of node, item, and name lists match when provided.
- Enhanced documentation for NodeObservation to reflect new functionality.
- Added unit tests to verify the new behavior, including auto-assignment and error handling for mismatched lengths.
@jpalm3r jpalm3r linked an issue Feb 23, 2026 that may be closed by this pull request
@jpalm3r jpalm3r removed a link to an issue Feb 23, 2026
@jpalm3r jpalm3r changed the base branch from main to japr/multinodeobs February 23, 2026 15:04
@jpalm3r jpalm3r changed the base branch from japr/multinodeobs to main February 23, 2026 15:05
@jpalm3r jpalm3r linked an issue Feb 23, 2026 that may be closed by this pull request
@jpalm3r jpalm3r mentioned this pull request Feb 24, 2026
@jpalm3r jpalm3r changed the base branch from main to japr/network-support February 27, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define network protocol

1 participant