Skip to content

[FIX] Remove _check_tfr_params from Transformer constructor#11004

Merged
larsoner merged 12 commits intomne-tools:mainfrom
Lund-Memory-Lab:time_frequency
Aug 15, 2022
Merged

[FIX] Remove _check_tfr_params from Transformer constructor#11004
larsoner merged 12 commits intomne-tools:mainfrom
Lund-Memory-Lab:time_frequency

Conversation

@DanielCSchad
Copy link
Copy Markdown
Contributor

Reference issue

Fixes #10971.

What does this implement/fix?

The mne.decoding.time_frequency.TimeFrequency transformer called the mne.time_frequency.tfr._check_tfr_params function in the constructor. This function violates scikit-learn best practices on estimators, since it modifies some of the input parameters.

This PR removes the call to _check_tfr_params, since it is called later in the _compute_tfr method anyway. The _check_option call can remain, since it doesn't modify parameters.

DanielCSchad and others added 8 commits July 28, 2022 16:40
Since the _check_tfr_param function changes some of the values it
checks, scikit-learn estimators must perform this check at runtime, not
during estimator instantiation. Failing to do so leads to an error.
If the constructor modifies non-default parameters, scikit-learn will
throw an error during cloning.
Checking and transforming in the constructor violates sklearn
best-practice. Since this check is already performed in the
`_compute_tfr` method, we can simply remove the check from the
transformer class.
Since options checking doesn't modify the value it makes sense to keep
it in the constructor.
@welcome
Copy link
Copy Markdown

welcome bot commented Aug 3, 2022

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴🏽‍♂️

@DanielCSchad
Copy link
Copy Markdown
Contributor Author

It seems like some of the tests failed due to CI issues (#11023 and #11012). I have merged the latest main, so hopefully that should resolve the failing tests.

@larsoner
Copy link
Copy Markdown
Member

Failing test is unrelated and being tackled in #11034. Thanks for looking into this @dod12 , I'll go ahead and merge!

If you're feeling motivated, you could add similar tests for all of our decoding classes, they probably need it...

@larsoner larsoner merged commit ec8a360 into mne-tools:main Aug 15, 2022
@welcome
Copy link
Copy Markdown

welcome bot commented Aug 15, 2022

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

@DanielCSchad DanielCSchad deleted the time_frequency branch August 19, 2022 15:11
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.

TimeFrequency Estimator modifies parameters in constructor

2 participants