Skip to content

Commit fcca1df

Browse files
committed
raise ValueError for unfitted idf vector
Catches an obscure AttributeError raised by calling .transform on a TfidfTransformer (with use_idf=True) that has not learned an idf vector.
1 parent f7c79fb commit fcca1df

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

sklearn/feature_extraction/text.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,8 @@ def transform(self, X, copy=True):
915915
X.data += 1
916916

917917
if self.use_idf:
918+
if not hasattr(self, "_idf_diag"):
919+
raise ValueError("idf vector not fitted")
918920
expected_n_features = self._idf_diag.shape[0]
919921
if n_features != expected_n_features:
920922
raise ValueError("Input has n_features=%d while the model"

0 commit comments

Comments
 (0)