-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor dmod.modeldata serialization and deserialization types #257
Merged
robertbartel
merged 24 commits into
NOAA-OWP:pydantic-serializable
from
aaraney:refactor-modeldata
Feb 22, 2023
Merged
Refactor dmod.modeldata serialization and deserialization types #257
robertbartel
merged 24 commits into
NOAA-OWP:pydantic-serializable
from
aaraney:refactor-modeldata
Feb 22, 2023
Conversation
This file contains 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
This was referenced Jan 26, 2023
…w factory init from dict
In writing some tests to accompany this PR I stumbled into a question. Is the below the desired behavior, @robertbartel? from dmod.modeldata.hydrofabric.partition import Partition, PartitionConfig
catchment_ids = ["1", "2", "3"]
partition_id = 0
o1 = Partition(
partition_id=partition_id,
catchment_ids=catchment_ids,
nexus_ids=["2"],
remote_up_nexuses=["1"],
remote_down_nexuses=["3"],
)
o2 = Partition(
partition_id=partition_id,
catchment_ids=catchment_ids,
nexus_ids=["2222"],
remote_up_nexuses=["1111"],
remote_down_nexuses=["3333"]
)
same_catchment_id_and_partition_id = PartitionConfig(partitions=[o1, o2])
assert len(same_catchment_id_and_partition_id.partitions) == 1 |
reasons why dict is overridden here: pydantic will serialize from inner types outward, serializing each type as a dictionary, list, or primitive and replacing its previous type with the new "serialized" type. Consequently, this means hashable container types like tuples and frozensets that contain values that "serialize" to a non-hashable type (non-primitive, in this case) will raise a `TypeError: unhashable type: 'dict'`. In the case of PartitionConfig, FronzenSet[Partition] "serializes" inner Partition types as dictionaries which are not hashable. To get around this, we will momentarily swap the `partitions` field for a non-hashable container type, serialize using `.dict()`, and swap back in the original `partitions` container.
aaraney
added a commit
to aaraney/DMOD
that referenced
this pull request
Feb 10, 2023
aaraney
added a commit
to aaraney/DMOD
that referenced
this pull request
Feb 10, 2023
… in 3.8 and is deprecated in 3.11
robertbartel
pushed a commit
to robertbartel/DMOD
that referenced
this pull request
Feb 16, 2023
robertbartel
pushed a commit
to robertbartel/DMOD
that referenced
this pull request
Feb 16, 2023
robertbartel
approved these changes
Feb 22, 2023
Thanks, @robertbartel! |
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.
This PR refactors
dmod.modeldata
'sdmod.core.serializable.Serializable
subtypes into compliance with the changes introduced in #239. These changes should not affect downstream usage ofdmod.modeldata
Serializable
subtypes.For broader context, implications, and examples regarding changes that affect the
Serializable
subtype, see #239.Changes
pydantic
added asdmod.modeldata
dependencyGitPython
, added todmod.modeldata
'ssetup.py
Checklist