Skip to content
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

[FIX] Remove _check_tfr_params from Transformer constructor #11004

Merged
merged 12 commits into from
Aug 15, 2022

Conversation

Dod12
Copy link
Contributor

@Dod12 Dod12 commented Aug 3, 2022

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.

Dod12 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

welcome bot commented Aug 3, 2022

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

@Dod12
Copy link
Contributor Author

Dod12 commented Aug 13, 2022

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
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

welcome bot commented Aug 15, 2022

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

@Dod12 Dod12 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