-
-
Notifications
You must be signed in to change notification settings - Fork 556
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
Full type hints for the module base #1668
base: main
Are you sure you want to change the base?
Conversation
We use Autotyping to add annotations where they are obvious from the context.
Arbitrary argument lists should be annotated with the type of the arguments and not as a tuple containing the type; unless the argument should all be tuples.
typing.Iterator is deprecated since Python 3.9.
The wrapped model can be any type of model, but only the classifiers have a _multiclass property. Before acessing it, we must make sure the attribute exists.
base.Transformer corresponds only to unbatched unsupervied transformers. Other transformers should also be accepted for grouping.
The Number interface matches all Python numbers and more. This includes complex numbers. Most formulas are intended to deal with real numbers only, and will error out if applied on ccomplex numbers. Moreover, MyPy does not recognise the interfaces for the 'number' module, and recommends to use Python's default numeric tower as proposed in PEP 484.
These error were indirectly caused by changes in `base`, where the stricter typing invalidates the previously ambiguous (but valid) type checks. These errors can be treated in their own modules.
Thanks for the info about
I like the
We could definitely simplify here: we don't have to inherit from |
Continuing #1592, this PR adds type hints for the
base
module.I am not entirely familiar with the code, so we may have things to adjust. Hence, I start with a draft.
Because the PR is quite big, I tried to have clean commits, you can use them to help the review.
Notable changes:
numbers
module for type annotations. And MyPy doesn't support it anyway.Also,
numers.Number
also includes complex numbers, but I am confident saying all the code expects floats. Integers are converted automatically to floats if needed.BaseTransformer
to allow all transformers, not just the supervised ones.A few things I would like to discuss before leaving the "draft" status:
The Estimator Problem: many functions expect a generic model that has the
predict_*
andlearn_*
methods, but there is no single type representing this capability.I tagged them as requiring an
Estimator
, but this is not satisfactory.Should we:
Classifier
,Regressor
,Clusterer
,Pipeline
)learn_*
andpredict_*
The
Ensemble
class inherits fromUserList
. Because it is an implementation of the list type, it is mutable, leading it to be type-invariant. SinceEnsemble
is now typed withEstimator
, all models are bare estimators. An ensemble of Hoeffding trees would not be able to access the HT-specific methods (even things likelearn_one
!) without violating the typing -- runtime behaviour is not impacted, Python is dynamic.