scikit-learn/scikit-learn — pull request #1656 by rlmv (2013-02-05 07:27:01+00:00)
Title: Fix AttributeError caused unlearned idf vector

Just a quick fix for a silly use case. If you call `transform` on a TfidfTransformer (with use_idf=True), and have not computed an idf_vector with `fit`, you get this error:
```
Traceback (most recent call last):
File "htcls.py", line 30, in
X = t.transform(X)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 918, in transform
expected_n_features = self._idf_diag.shape[0]
AttributeError: 'TfidfTransformer' object has no attribute '_idf_diag'
```

This PR checks that the Transformer has the _idf_diag attribute before accessing it, and if not raises a ValueError describing why.