-
Notifications
You must be signed in to change notification settings - Fork 20
Convert AnalysisOptions to Pydantic (Issue #78) #93
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
base: master
Are you sure you want to change the base?
Convert AnalysisOptions to Pydantic (Issue #78) #93
Conversation
henrikingo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @yongminkim0501 and welcome!
As the person who wrote most of those to_json() methods, I'm glad to see them go away!
I have just one small comment, if you can make that change, I'll merge this. And yes by all means, please continue this with remaining classes.
| self.min_magnitude = 0.0 | ||
| self.orig_edivisive = False | ||
|
|
||
| def to_json(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until the next release, let's try to keep some superficial backward compatibility. (After that we will make big changes anyway, so then this can be removed.)
Could you keep all to_json() functions and make them do something like:
@deprecated
def to_json(self):
return self.dict()
These functions are called by outside code that depends on otava, so this could ease the pain if upgrading to the next release. (At the same time, note that we don't promise and don't test for strict backward combatibility at this stage of the projects lifecycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! I'll update the PR to deprecate the to_json() methods
instead of removing them. Will commit the changes shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve applied the requested changes and pushed a possible fix for the suspected error. I’d appreciate it if you could take a look.
454dc10 to
6a383d0
Compare
- Convert data classes to Pydantic BaseModel - Deprecate to_json() methods with DeprecationWarning - Update all instantiations to use keyword arguments - Add arbitrary_types_allowed config for nested models Results: 11/12 tests passing Note: test_orig_edivisive reveals a pre-existing issue where compute_change_points_orig() returns EDivisive library objects instead of ChangePoint objects. Could you help me understand how to properly handle this case?
6a383d0 to
39064a3
Compare
|
This question was in my emails, although it seem to have disappeared from github...
'''python Before After (Pydantic)
Hmm... Good catch ... Ok so testing and googling a little myself, I learn that if we want to preserve backward compatibility, maybe you should look into https://docs.pydantic.dev/1.10/usage/dataclasses/ Now that 0.7.0 release is already in the owen... Let me also repeat that if we just wait past that release, there's no need to maintain any backward compatibility. Instead, we can discuss about what is our preferred way to maintain these data models? For example, my personal view would be:
I'll now look into your other questions and re-review what changed. |
|
Ok so nothing inherently wrong in the patch and no other comments for now. But I suggest you look into pydantic.dataclass next, and if that works and helps us get rid of the to_json()/from_json() functions, then even this very patch will become simpler, as tests should just continue to work as they are. |
|
Thanks for the suggestion! I'll use pydantic.dataclass to make the tests pass while maintaining backward compatibility. Looking forward to discussing the preferred approach for data model management after the 0.7.0 release! |
Overview
This PR converts the 'AnalysisOptions' class to use Pydantic for more pythonic serialization, as suggested in #78
Changes
Technical Issue
typing-extensionsversion conflict withsignal-processing-algorithms==1.3.5Testing
Future work
Related Issue
Part of #78