Skip to content

Make check_parameters_default_constructible more lenient regarding accepted types #25467

@glemaitre

Description

@glemaitre

With the nightly build of numpy, we have the following error raised:

               allowed_types = {
                    str,
                    int,
                    float,
                    bool,
                    tuple,
                    type(None),
                    type,
                    types.FunctionType,
                    joblib.Memory,
                }
                # Any numpy numeric such as np.int32.
                allowed_types.update(np.core.numerictypes.allTypes.values())
>               assert type(init_param.default) in allowed_types, (
                    f"Parameter '{init_param.name}' of estimator "
                    f"'{Estimator.__name__}' is of type "
                    f"{type(init_param.default).__name__} which is not "
                    "allowed. All init parameters have to be immutable to "
                    "make cloning possible. Therefore we restrict the set of "
                    "legal types to "
                    f"{set(type.__name__ for type in allowed_types)}."
                )
E               AssertionError: Parameter 'pooling_func' of estimator 'FeatureAgglomeration' is of type _ArrayFunctionDispatcher which is not allowed. All init parameters have to be immutable to make cloning possible. Therefore we restrict the set of legal types to {'bool_', 'int64', 'datetime64', 'complex128', 'int8', 'object_', 'bool', 'float16', 'float32', 'tuple', 'str', 'longlong', 'complex64', 'generic', 'int', 'uint64', 'float128', 'int32', 'floating', 'complex256', 'uint32', 'float', 'integer', 'timedelta64', 'type', 'uint16', 'function', 'int16', 'void', 'Memory', 'flexible', 'complexfloating', 'float64', 'unsignedinteger', 'bytes_', 'signedinteger', 'NoneType', 'number', 'uint8', 'character', 'inexact', 'ulonglong', 'str_'}.

I think this is linked with the integration of: numpy/numpy#23020

Now, the np.func are of type _ArrayFunctionDispatcher and not function anymore. This is a kind of regression but I assume that we could make our test more lenient and accept those types of input.

The only issue is that this dispatcher is private so I don't think this is a bright idea to add it to our test as is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions