scikit-learn/scikit-learn — pull request #2636 by jseabold (2013-12-05 09:02:07+00:00)
Title: ENH: Raise explicitly on non-unique vocab.

A little better error message in this case. It's a bit ugly, but AFAICT there's not a better way since the user may give an object without a `__len__`.

Incidentally, what are the thoughts on just handling non-unique vocabularies? Something like

```
vocabulary = list(set(vocabulary))
```

This won't work because things like this that are actually mappings would get clobbered by the current check for a mapping.

```
vocab = {"vocab" : 0, "beer" : 1}

from collections import Mapping

isinstance(iter(vocab), Mapping)
```

But it seems like it would be nice to just do this, if possible. Maybe raise a warning that the feature names of the vectorizer are now different than the given vocabulary. Thoughts?