Repository navigation
Improves ClassList integration with Pydantic and adds JSON conversion for Projects - #79
Merged
Merged
Conversation
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.
This PR solves #76 by allowing
Projects to be read and written from JSON via two new functions,project_to_jsonandproject_from_json.Changes
ClassListis now aGenericclass, improving compatibility with static type checkers (e.g. you can now writeClassList[Parameter], and type checking will know a priori that theClassListshould haveParameters in it)ClassLists, which means that Pydantic can validate them automatically. The type of theClassListis specified using square brackets, e.g. aClassListof strings would beClassList[str]. This schema does the following:ClassList, and raise aValidationErrorif the list types are not homogeneousClassList[T].dataas though it were alist[T]type, i.e. ensure that all entries in theClassListare the type expected by the model.Projectrather than aClassListand it will be converted automaticallyClassListcan be given as dictionariesFor example, the following are now all valid inputs to a Project:
In future, once Pydantic has integrated Numpy support (pydantic/pydantic#9677), this will be good enough for us to use Pydantic's
model_dump_jsonto saveProjects in JSON format (via converting eachClassListofRATModels to a list of dictionaries, as it now knows how to get back from that). But for now:convert_to_jsonandconvert_from_jsonwhich convert aProjectto and from JSON format, with workarounds to handleClassLists and the Numpy array in theDatamodel.