Gensim: FutureWarning: Conversion of the second argument of issubdtype from `int` to `np.signedinteger` is deprecated

Created on 16 Sep 2018  路  5Comments  路  Source: RaRe-Technologies/gensim

Description

/usr/lib/python3.7/site-packages/gensim/matutils.py:737: FutureWarning: Conversion of the second argument of issubdtype from `int` to `np.signedinteger` is deprecated. In future, it will be treated as `np.int64 == np.dtype(int).type`.
  if np.issubdtype(vec.dtype, np.int):

Steps/Code/Corpus to Reproduce

from gensim.test.utils import common_texts
from gensim.models import Word2Vec

model = Word2Vec(common_texts, size=100, window=5, min_count=1, workers=4)
print(model.wv.most_similar('human'))

Expected Results

No warning.

Actual Results

FutureWarning.

Versions

Linux-4.14.68-1-MANJARO-x86_64-with-arch-Manjaro-Linux
Python 3.7.0 (default, Jul 15 2018, 10:44:58) 
[GCC 8.1.1 20180531]
NumPy 1.15.1
SciPy 1.1.0
gensim 3.5.0
FAST_VERSION 0

Possible fix

Replace the offending line with

if np.issubdtype(vec.dtype, np.signedinteger) or np.issubdtype(vec.dtype, np.unsignedinteger):

Based on Numpy docs. I haven't researched the issue thoroughly though and I'm not sure whether this is a proper fix.

Hacktoberfest bug difficulty easy

Most helpful comment

Hello, I am still receiving this error. My versions are:
Python - 3.7
numpy - 1.15.4
gensim - 3.6.0

Well, the Fix was implemented on 3rd Oct - the last release was 3.6.0 (September '18), so I think you have to wait for the next release-date ;)

All 5 comments

@Pastafarianist thanks for the report, issue reproduced using mentioned dependencies.

if veclen > 0.0:

        if np.issubdtype(vec.dtype, np.int):
            vec = vec.astype(np.float)
        vec /= veclen
        if return_norm:
            return vec, veclen
        else:
            return vec

In the particular code, np.issubdtype returns True if first argument is a typecode lower/equal in type hierarchy. As np.int and np.signedinteger both are of int32 type, so here we should replace np.int by np.int64 to get the highest int type hierarchy(second argument) to remove the FutureWarning. Am I thinking correct??

@aquatiko

so here we should replace np.int by np.int64 to get the highest int type hierarchy

no, for example, int32 isn't "child type" for int64

>>> isinstance(np.int32, np.int64)
False

Hello, I am still receiving this error. My versions are:
Python - 3.7
numpy - 1.15.4
gensim - 3.6.0

this is the code I am trying to run:
image

this is my output:
image

I am new to gensim and have very little python experience, so I'm not sure if this issue is on my end or not. It seems to be the same though. Any help is appreciated.

Edit: I noticed that my error is about np.int32, where the previous error is np.int64

Hello, I am still receiving this error. My versions are:
Python - 3.7
numpy - 1.15.4
gensim - 3.6.0

Well, the Fix was implemented on 3rd Oct - the last release was 3.6.0 (September '18), so I think you have to wait for the next release-date ;)

Was this page helpful?
0 / 5 - 0 ratings