Skip to content
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

pylance warning - Argument of type "list[LGBMRegressor]" cannot be assigned to parameter "models" of type "Models" in function "init" #411

Open
sumamjose opened this issue Sep 4, 2024 · 0 comments

Comments

@sumamjose
Copy link

sumamjose commented Sep 4, 2024

Description

I'm encountering a type mismatch issue when passing a list of models (regressors) to the MLForecast class. The documentation states that the models parameter can be either a single regressor or a list of regressors as in https://github.com/Nixtla/mlforecast/blob/main/mlforecast/forecast.py#L126. However, when passing a list of models or the model alone, I receive a type error indicating that Argument of type "list[LGBMRegressor]" cannot be assigned to parameter "models" of type "Models" in function "init"

Python 3.10.12
mlforecast 0.13.4

According to the documentation:

Parameters

models : regressor or list of regressors
Models that will be trained and used to compute the forecasts.

Sample code:


Import necessary libraries

from mlforecast import MLForecast
import lightgbm as lgb
from sklearn.linear_model import LinearRegression
import pandas as pd

Create a simple DataFrame to simulate data

train_df = pd.DataFrame({
'ds': pd.date_range(start='2020-01-01', periods=100, freq='D'),
'y': range(100),
})

Define a list of models

models = [
lgb.LGBMRegressor(random_state=0, verbosity=-1),
LinearRegression(),
]

Initialize MLForecast with the list of models

try:
fcst = MLForecast(models=models, freq='D')
print("Model initialized successfully.")
except TypeError as e:
print(f"Encountered an error: {e}")


the above code works fine without warning, but when using

models = [lgb.LGBMRegressor(random_state=0, verbosity=-1)]
or
models = lgb.LGBMRegressor(random_state=0, verbosity=-1)

it gives respective pylance warnings as below in vscode:

Argument of type "list[LGBMRegressor]" cannot be assigned to parameter "models" of type "Models" in function "init"
Type "list[LGBMRegressor]" is incompatible with type "Models"
"list[LGBMRegressor]" is incompatible with "BaseEstimator"
"list[LGBMRegressor]" is incompatible with "List[BaseEstimator]"
Type parameter "_T@list" is invariant, but "LGBMRegressor" is not the same as "BaseEstimator"
Consider switching from "list" to "Sequence" which is covariant
"list[LGBMRegressor]" is incompatible with "Dict[str, BaseEstimator]"PylancereportArgumentType

or

Argument of type "LGBMRegressor" cannot be assigned to parameter "models" of type "Models" in function "init"
Type "LGBMRegressor" is incompatible with type "Models"
"LGBMRegressor" is incompatible with "BaseEstimator"
"LGBMRegressor" is incompatible with "List[BaseEstimator]"
"LGBMRegressor" is incompatible with "Dict[str, BaseEstimator]"PylancereportArgumentType

Could you please look into why that is happening despite the documentation?

Link

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant