Skip to content

Commit

Permalink
Fix np.issubdtype warnings (#2210)
Browse files Browse the repository at this point in the history
* modify check of subsinstances of np.int for subinstances of np.signedinteger and np.unsignedinteger

* change to np.integer and np.floating
  • Loading branch information
marioyc authored and menshikh-iv committed Oct 5, 2018
1 parent 6a97463 commit 61a42da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gensim/matutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def unitvec(vec, norm='l2', return_norm=False):
if norm == 'l2':
veclen = np.sqrt(np.sum(vec.data ** 2))
if veclen > 0.0:
if np.issubdtype(vec.dtype, np.int):
if np.issubdtype(vec.dtype, np.integer):
vec = vec.astype(np.float)
vec /= veclen
if return_norm:
Expand All @@ -734,7 +734,7 @@ def unitvec(vec, norm='l2', return_norm=False):
if norm == 'l2':
veclen = blas_nrm2(vec)
if veclen > 0.0:
if np.issubdtype(vec.dtype, np.int):
if np.issubdtype(vec.dtype, np.integer):
vec = vec.astype(np.float)
if return_norm:
return blas_scal(1.0 / veclen, vec).astype(vec.dtype), veclen
Expand Down
16 changes: 8 additions & 8 deletions gensim/test/test_ldamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ def testTopTopics(self):

for v, k in topic:
self.assertTrue(isinstance(k, six.string_types))
self.assertTrue(np.issubdtype(v, float))
self.assertTrue(np.issubdtype(v, np.floating))

def testGetTopicTerms(self):
topic_terms = self.model.get_topic_terms(1)

for k, v in topic_terms:
self.assertTrue(isinstance(k, numbers.Integral))
self.assertTrue(np.issubdtype(v, float))
self.assertTrue(np.issubdtype(v, np.floating))

def testGetDocumentTopics(self):

Expand All @@ -222,7 +222,7 @@ def testGetDocumentTopics(self):
self.assertTrue(isinstance(topic, list))
for k, v in topic:
self.assertTrue(isinstance(k, numbers.Integral))
self.assertTrue(np.issubdtype(v, float))
self.assertTrue(np.issubdtype(v, np.floating))

# Test case to use the get_document_topic function for the corpus
all_topics = model.get_document_topics(self.corpus, per_word_topics=True)
Expand All @@ -233,7 +233,7 @@ def testGetDocumentTopics(self):
self.assertTrue(isinstance(topic, tuple))
for k, v in topic[0]: # list of doc_topics
self.assertTrue(isinstance(k, numbers.Integral))
self.assertTrue(np.issubdtype(v, float))
self.assertTrue(np.issubdtype(v, np.floating))

for w, topic_list in topic[1]: # list of word_topics
self.assertTrue(isinstance(w, numbers.Integral))
Expand All @@ -257,7 +257,7 @@ def testGetDocumentTopics(self):
self.assertTrue(isinstance(topic, tuple))
for k, v in topic[0]: # list of doc_topics
self.assertTrue(isinstance(k, numbers.Integral))
self.assertTrue(np.issubdtype(v, float))
self.assertTrue(np.issubdtype(v, np.floating))
if len(topic[0]) != 0:
doc_topic_count_na += 1

Expand All @@ -278,7 +278,7 @@ def testGetDocumentTopics(self):

for k, v in doc_topics:
self.assertTrue(isinstance(k, numbers.Integral))
self.assertTrue(np.issubdtype(v, float))
self.assertTrue(np.issubdtype(v, np.floating))

for w, topic_list in word_topics:
self.assertTrue(isinstance(w, numbers.Integral))
Expand Down Expand Up @@ -306,7 +306,7 @@ def testTermTopics(self):
result = model.get_term_topics(2)
for topic_no, probability in result:
self.assertTrue(isinstance(topic_no, int))
self.assertTrue(np.issubdtype(probability, float))
self.assertTrue(np.issubdtype(probability, np.floating))

# checks if topic '1' is in the result list
# FIXME: Fails on osx and win
Expand All @@ -316,7 +316,7 @@ def testTermTopics(self):
result = model.get_term_topics(str(model.id2word[2]))
for topic_no, probability in result:
self.assertTrue(isinstance(topic_no, int))
self.assertTrue(np.issubdtype(probability, float))
self.assertTrue(np.issubdtype(probability, np.floating))

# checks if topic '1' is in the result list
# FIXME: Fails on osx and win
Expand Down
12 changes: 6 additions & 6 deletions gensim/test/test_matutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ def test_sparse_npint32(self):
unit_vector = matutils.unitvec(input_vector)
man_unit_vector = manual_unitvec(input_vector)
self.assertTrue(np.allclose(unit_vector.data, man_unit_vector.data, atol=1e-3))
self.assertTrue(np.issubdtype(unit_vector.dtype, float))
self.assertTrue(np.issubdtype(unit_vector.dtype, np.floating))

def test_sparse_npint64(self):
input_vector = sparse.csr_matrix(np.asarray([[1, 0, 0, 0, 3], [0, 0, 4, 3, 0]])).astype(np.int64)
unit_vector = matutils.unitvec(input_vector)
man_unit_vector = manual_unitvec(input_vector)
self.assertTrue(np.allclose(unit_vector.data, man_unit_vector.data, atol=1e-3))
self.assertTrue(np.issubdtype(unit_vector.dtype, float))
self.assertTrue(np.issubdtype(unit_vector.dtype, np.floating))

def test_dense_npfloat32(self):
input_vector = np.random.uniform(size=(5,)).astype(np.float32)
Expand All @@ -204,14 +204,14 @@ def test_dense_npint32(self):
unit_vector = matutils.unitvec(input_vector)
man_unit_vector = manual_unitvec(input_vector)
self.assertTrue(np.allclose(unit_vector, man_unit_vector))
self.assertTrue(np.issubdtype(unit_vector.dtype, float))
self.assertTrue(np.issubdtype(unit_vector.dtype, np.floating))

def test_dense_npint64(self):
input_vector = np.random.randint(10, size=5).astype(np.int32)
unit_vector = matutils.unitvec(input_vector)
man_unit_vector = manual_unitvec(input_vector)
self.assertTrue(np.allclose(unit_vector, man_unit_vector))
self.assertTrue(np.issubdtype(unit_vector.dtype, float))
self.assertTrue(np.issubdtype(unit_vector.dtype, np.floating))

def test_sparse_python_float(self):
input_vector = sparse.csr_matrix(np.asarray([[1, 0, 0, 0, 3], [0, 0, 4, 3, 0]])).astype(float)
Expand All @@ -225,7 +225,7 @@ def test_sparse_python_int(self):
unit_vector = matutils.unitvec(input_vector)
man_unit_vector = manual_unitvec(input_vector)
self.assertTrue(np.allclose(unit_vector.data, man_unit_vector.data, atol=1e-3))
self.assertTrue(np.issubdtype(unit_vector.dtype, float))
self.assertTrue(np.issubdtype(unit_vector.dtype, np.floating))

def test_dense_python_float(self):
input_vector = np.random.uniform(size=(5,)).astype(float)
Expand All @@ -239,7 +239,7 @@ def test_dense_python_int(self):
unit_vector = matutils.unitvec(input_vector)
man_unit_vector = manual_unitvec(input_vector)
self.assertTrue(np.allclose(unit_vector, man_unit_vector))
self.assertTrue(np.issubdtype(unit_vector.dtype, float))
self.assertTrue(np.issubdtype(unit_vector.dtype, np.floating))


if __name__ == '__main__':
Expand Down

0 comments on commit 61a42da

Please sign in to comment.