[MNT] Remove mutable objects from defaults#1699
Conversation
…ata and pytorch_forecasting.metrics
fkiraly
left a comment
There was a problem hiding this comment.
Nice!
I think this is great and can be in a single PR.
Some small issues:
- the tests are failing due to type annotations, have a look at the logs
- not a strict requirement, but it might be safer in case of
__init__to write the resolved argument to a parameterself._parametername, to ensureself.parameternameis always identical with the__init__input. This is a "dataclass-like" interface which may be useful later in interfacing sklearn and similar libraries.
I see, thanks for the feedback! |
There was a problem hiding this comment.
Looks great!
Though, for the __init__-s, you would still do self.paramname = paramname, just not change it, e.g.,
self.groups = groups
self._groups = do_sth_with_groups(groups)so the class behaves like a dataclass with respect to its init parameters.
There were also a lot of linting failures related to the introduction of stricter requirements in ruff, I fixed most of them. The remaining ones seem genuine code issues, could you have ea look?
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
Just for me to understand, let's take the
we do: then we would have to refactor usages of |
Yes, exactly what I mean. The high-level rationale is that the class then behaves, at all times of usage, like a |
…arguments within the class + removed properties
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
@fkiraly added changes based on the above. Could you take a look? |
|
@fkiraly are there any adjustments needed or good to merge? |
fkiraly
left a comment
There was a problem hiding this comment.
Looks good to me!
Sorry, I thought I had replied.
Description
This PR is a fix for #1668. Removes mutable default arguments and replaces them with internal newly initialized mutable defaults.
Checklist
pre-commit install.To run hooks independent of commit, execute
pre-commit run --all-files