-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
D2VTransformer raises if passed a Pandas series without index key 0 #2556
Comments
TODO: check other |
So I need to check here for the first element, not element at index 0? |
@piskvorky ready for review and, hopefully, a merge. |
@Hiyorimi just looking at this code again, I've realized we're making a copy of a list. This is unnecessary: if isinstance([i for i in X[:1]][0], doc2vec.TaggedDocument):
d2v_sentences = X
d2v_sentences = X You could do something like: def _get_first(some_list):
for elem in some_list:
return elem
...
if isinstance(_get_first(X), doc2vec.TaggedDocument):
d2v_sentences = X
d2v_sentences = X WDYT? |
Are you sure that it is better rather than making a copy of a slice? |
Not 100%. Making a copy of the list seems wasteful, though. Do you disagree? |
It is 1 line + copy of 1 element I have no clue what is better here. |
The standard way to get the first element of a repeatable iterable is For non-repeatable generators, it's a bit more complicated, because we must put the "peeked" first element back after peeking. Otherwise we would change What is the type of
|
Since >>> a = pd.DataFrame([[1,2], [2,4]], columns=['1', '2'])
>>> a.index += 1
>>> _get_first = lambda X: next(iter(X))
>>> _get_first(a)
'1' I just added method. |
Opened a PR |
D2VTransformer
raises if passed a Pandas series with an index that does not contain the key 0:Output:
This occurs because the
fit
andtransform
methods ofD2VTransformer
require__getitem__
on the passed iterable not to raise an exception for key 0.Versions:
Darwin-18.6.0-x86_64-i386-64bit
Python 3.7.3 (default, Mar 27 2019, 09:23:15) [Clang 10.0.1 (clang-1001.0.46.3)]
NumPy 1.16.4
SciPy 1.3.0
gensim 3.8.0
FAST_VERSION 1
The text was updated successfully, but these errors were encountered: