From c1a1d26d10d8d76b6650f511e8cf71b6b2ae4af0 Mon Sep 17 00:00:00 2001 From: jrzaurin Date: Sat, 7 Dec 2019 15:14:59 +0000 Subject: [PATCH] adapted the code so it runs with the newest sklearn version 0.22 --- pytorch_widedeep/preprocessing/_preprocessors.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pytorch_widedeep/preprocessing/_preprocessors.py b/pytorch_widedeep/preprocessing/_preprocessors.py index 9078bcc..e17f69b 100644 --- a/pytorch_widedeep/preprocessing/_preprocessors.py +++ b/pytorch_widedeep/preprocessing/_preprocessors.py @@ -6,6 +6,7 @@ import cv2 from sklearn.preprocessing import OneHotEncoder from sklearn.preprocessing import StandardScaler from sklearn.utils.validation import check_is_fitted +from sklearn.exceptions import NotFittedError from scipy.sparse import csc_matrix from tqdm import tqdm @@ -293,7 +294,11 @@ class TextPreprocessor(BasePreprocessor): return self def transform(self, df:pd.DataFrame, text_col:str)->np.ndarray: - check_is_fitted(self, 'vocab') + try: + self.vocab + except: + raise NotFittedError("This TextPreprocessor instance is not fitted yet. " + "Call 'fit' with appropriate arguments before using this estimator.") self.text_col = text_col texts = df[self.text_col].tolist() self.tokens = get_texts(texts) @@ -363,7 +368,11 @@ class ImagePreprocessor(BasePreprocessor): return self def transform(self, df, img_col:str, img_path:str)->np.ndarray: - check_is_fitted(self, 'aap') + try: + self.app + except: + raise NotFittedError("This ImagePreprocessor instance is not fitted yet. " + "Call 'fit' with appropriate arguments before using this estimator.") self.img_col = img_col image_list = df[self.img_col].tolist() if self.verbose: print('Reading Images from {}'.format(img_path)) -- GitLab