Use more assert for checking the variable properties.
#31920
lionelkusch
started this conversation in
Ideas
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
By looking at the code, I see that most of the checks of the variable are based on the next schema:
For example,
scikit-learn/sklearn/neighbors/_nca.py
Lines 248 to 292 in 24844a0
I am wondering why the assertion is not used in this case.
The advantage of assertion is that there can be deactivate it by option "-O" of python and it can increase the speed of execution of a program, especially in the case of a pipeline.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments
Uh oh!
There was an error while loading. Please reload this page.
-
assertisn't used for input validation in scikit-learn because assertions can be disabled with-O, which would skip important checks and break API guarantees.ValueError/TypeErrorare used intentionally so validation always runs.Beta Was this translation helpful? Give feedback.
All reactions
Uh oh!
There was an error while loading. Please reload this page.
-
This is the point of using assertions: to disable the checks when they're not required.
Once you are sure of what you are doing, we should have a way to speed up the calculation by removing the check especially when we are doing hyperparameter optimisation.
Beta Was this translation helpful? Give feedback.
All reactions