improve error message for required packages (#4304)

This commit is contained in:
Nikita Titov 2021-05-20 22:33:20 +03:00 коммит произвёл GitHub
Родитель 272fedb95a
Коммит f076ca58b3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 11 добавлений и 8 удалений

Просмотреть файл

@ -6,7 +6,7 @@ import lightgbm as lgb
if lgb.compat.MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt
else:
raise ImportError('You need to install matplotlib for plot_example.py.')
raise ImportError('You need to install matplotlib and restart your session for plot_example.py.')
print('Loading data...')
# load or create your dataset

Просмотреть файл

@ -2085,7 +2085,8 @@ class Dataset:
elif isinstance(self.data, pd_DataFrame):
if not PANDAS_INSTALLED:
raise LightGBMError("Cannot add features to DataFrame type of raw data "
"without pandas installed")
"without pandas installed. "
"Install pandas and restart your session.")
if isinstance(other.data, np.ndarray):
self.data = concat((self.data, pd_DataFrame(other.data)),
axis=1, ignore_index=True)
@ -2402,7 +2403,8 @@ class Booster:
Returns a pandas DataFrame of the parsed model.
"""
if not PANDAS_INSTALLED:
raise LightGBMError('This method cannot be run without pandas installed')
raise LightGBMError('This method cannot be run without pandas installed. '
'You must install pandas and restart your session to use this method.')
if self.num_trees() == 0:
raise LightGBMError('There are no trees in this Booster and thus nothing to parse')

Просмотреть файл

@ -80,7 +80,7 @@ def plot_importance(booster, ax=None, height=0.2,
if MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt
else:
raise ImportError('You must install matplotlib to plot importance.')
raise ImportError('You must install matplotlib and restart your session to plot importance.')
if isinstance(booster, LGBMModel):
booster = booster.booster_
@ -197,7 +197,7 @@ def plot_split_value_histogram(booster, feature, bins=None, ax=None, width_coef=
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
else:
raise ImportError('You must install matplotlib to plot split value histogram.')
raise ImportError('You must install matplotlib and restart your session to plot split value histogram.')
if isinstance(booster, LGBMModel):
booster = booster.booster_
@ -294,7 +294,7 @@ def plot_metric(booster, metric=None, dataset_names=None,
if MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt
else:
raise ImportError('You must install matplotlib to plot metric.')
raise ImportError('You must install matplotlib and restart your session to plot metric.')
if isinstance(booster, LGBMModel):
eval_results = deepcopy(booster.evals_result_)
@ -602,7 +602,7 @@ def plot_tree(booster, ax=None, tree_index=0, figsize=None, dpi=None,
import matplotlib.image as image
import matplotlib.pyplot as plt
else:
raise ImportError('You must install matplotlib to plot tree.')
raise ImportError('You must install matplotlib and restart your session to plot tree.')
if ax is None:
if figsize is not None:

Просмотреть файл

@ -461,7 +461,8 @@ class LGBMModel(_LGBMModelBase):
and you should group grad and hess in this way as well.
"""
if not SKLEARN_INSTALLED:
raise LightGBMError('scikit-learn is required for lightgbm.sklearn')
raise LightGBMError('scikit-learn is required for lightgbm.sklearn. '
'You must install scikit-learn and restart your session to use this module.')
self.boosting_type = boosting_type
self.objective = objective