giotto-ai / giotto-tda

A high-performance topological machine learning toolbox in Python
https://giotto-ai.github.io/gtda-docs
Other
845 stars 173 forks source link

Fix and improve validate_params #502

Closed ulupo closed 4 years ago

ulupo commented 4 years ago

Reference issues/PRs Motivated by discussion in #479.

Types of changes

Description I found that validate_params did not work as intended when allowed types are in a tuple. The 'of' key was ignored in that case. So e.g. in

hyperparameters = {"parameter": {"type": (type(None), np.ndarray), "of": {"type": np.float}}}

the type of each entry in the case of ndarray was not actually being checked to be an instance of np.float. Furthermore, a simple fix allows to address the case relevant to #479 of tuples of types including list-like and numeric types. Previously, it would not be possible to have both an 'in' and an 'of' key. Now it is, and 'in' is only used for non-list-like types, and 'of' otherwise.

Checklist