pythonvisual-studio-codepylancemicromamba

PyLance incorrectly flagging sklearn mean_squared_error function as deprecated


I haven't been able to find anything online about this. Pylance seems to be marking the mean_squared_error function from sklearn.metrics as deprecated, although only the squared parameter is deprecated.

I am running Python through micromamba and have the latest version of both sklearn (1.5.2) and Pylance (v2024.10.1).

Screenshot of warning

I have uninstalled and reinstalled scikit-learn in my micromamba environment as well as updating micromamba itself.


Solution

  • Pyright/Pylance made no mistake, and neither did you. This is a problem with the type stubs for sklearn.metrics, in which mean_squared_error is defined as:

    @deprecated()
    def mean_squared_error(
        y_true: MatrixLike | ArrayLike,
        y_pred: MatrixLike | ArrayLike,
        *,
        sample_weight: None | ArrayLike = None,
        multioutput: ArrayLike | Literal["raw_values", "uniform_average", "uniform_average"] = "uniform_average",
        squared: bool = True,
    ) -> ndarray | Float: ...
    

    The decorator was added recently in this PR. I created an issue and submitted a fix. Since these stubs come with Pylance, you will have to wait for the next version of Pylance with which the fix is included.

    In the meantime, you can either ignore the warning or enable the python.analysis.disableTaggedHints setting: