nubank / fklearn

fklearn: Functional Machine Learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Code Style] Do not use asserts to check correct input-args, raise errors

jdemonasterio opened this issue · comments

Describe the feature and the current state.

This would be more of a suggestion than a feature or bug, as it is effectively a subjective matter which may be ignored. However, it'd be great to start adopting a coding style more in line with what other great python packages are doing.

Looking at the source code for example, here you assert that the function's input args are correct

assert (proportion > 0.0) & (proportion < 1.0), "proportions must be between 0 and 1"

However a better widespread practice is to raiseErrors for these cases.
https://github.com/google/styleguide/blob/gh-pages/pyguide.md#244-decision

Make use of built-in exception classes when it makes sense. 
For example, raise a ValueError if you were passed a negative number but were expecting a positive one. 
Do not use assert statements for validating argument values of a public API. 
assert is used to ensure internal correctness, not to enforce correct usage nor to indicate that some unexpected event occurred. 
If an exception is desired in the latter cases, use a raise statement.

More in general, this feature request can be extended to adopt a more widespread code-style, such as the one in the aforementioned pyguide.

Will this change a current behavior? How?

Some fair amount of code would change, mostly in error/exceptions handling.

Additional Information

cc @darlansf1