Skip to content
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

Fix some of the warnings/ deprecated functions #3080

Merged
merged 3 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gensim/matutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def unitvec(vec, norm='l2', return_norm=False):
veclen = vec.nnz
if veclen > 0.0:
if np.issubdtype(vec.dtype, np.integer):
vec = vec.astype(np.float)
vec = vec.astype(float)
vec /= veclen
if return_norm:
return vec, veclen
Expand All @@ -748,7 +748,7 @@ def unitvec(vec, norm='l2', return_norm=False):
veclen = np.count_nonzero(vec)
if veclen > 0.0:
if np.issubdtype(vec.dtype, np.integer):
vec = vec.astype(np.float)
vec = vec.astype(float)
if return_norm:
return blas_scal(1.0 / veclen, vec).astype(vec.dtype), veclen
else:
Expand Down
12 changes: 6 additions & 6 deletions gensim/models/atmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@ def inference(self, chunk, author2doc, doc2author, rhot, collect_sstats=False, c
ids = [int(idx) for idx, _ in doc]
else:
ids = [idx for idx, _ in doc]
ids = np.array(ids, dtype=np.int)
cts = np.fromiter((cnt for _, cnt in doc), dtype=np.int, count=len(doc))
ids = np.array(ids, dtype=int)
cts = np.fromiter((cnt for _, cnt in doc), dtype=int, count=len(doc))

# Get all authors in current document, and convert the author names to integer IDs.
authors_d = np.fromiter((self.author2id[a] for a in self.doc2author[doc_no]), dtype=np.int)
authors_d = np.fromiter((self.author2id[a] for a in self.doc2author[doc_no]), dtype=int)

gammad = self.state.gamma[authors_d, :] # gamma of document d before update.
tilde_gamma = gammad.copy() # gamma that will be updated.
Expand Down Expand Up @@ -975,9 +975,9 @@ def bound(self, chunk, chunk_doc_idx=None, subsample_ratio=1.0, author2doc=None,
else:
doc_no = d
# Get all authors in current document, and convert the author names to integer IDs.
authors_d = np.fromiter((self.author2id[a] for a in self.doc2author[doc_no]), dtype=np.int)
ids = np.fromiter((id for id, _ in doc), dtype=np.int, count=len(doc)) # Word IDs in doc.
cts = np.fromiter((cnt for _, cnt in doc), dtype=np.int, count=len(doc)) # Word counts.
authors_d = np.fromiter((self.author2id[a] for a in self.doc2author[doc_no]), dtype=int)
ids = np.fromiter((id for id, _ in doc), dtype=int, count=len(doc)) # Word IDs in doc.
cts = np.fromiter((cnt for _, cnt in doc), dtype=int, count=len(doc)) # Word counts.

if d % self.chunksize == 0:
logger.debug("bound: at document #%i in chunk", d)
Expand Down
2 changes: 1 addition & 1 deletion gensim/models/keyedvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def add_vectors(self, keys, weights, extras=None, replace=False):
# initially allocate extras, check type compatibility
self.allocate_vecattrs(extras.keys(), [extras[k].dtype for k in extras.keys()])

in_vocab_mask = np.zeros(len(keys), dtype=np.bool)
in_vocab_mask = np.zeros(len(keys), dtype=bool)
for idx, key in enumerate(keys):
if key in self:
in_vocab_mask[idx] = True
Expand Down
3 changes: 2 additions & 1 deletion gensim/models/nmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@

"""

import collections

import collections.abc as collections
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any real benefit in doing this instead of:

Suggested change
import collections.abc as collections
import collections.abc

You're saving 4 characters, but making it less obvious what's actually being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of keeping small diffs at the time but I agree that it would make more sense to change it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is a somewhat valid reason, but think about the trade-off:

  1. We do a bit more work during this review (one-off cost)
  2. People reading the code may be confused (repetitive cost)

Better to pay once up front and save future generations of gensim developers the pain (I'm exaggerating, obviously, but you probably get my point).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah absolutely! I'll get that changed. Hopefully I'll have it sorted in a couple hours

import logging

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion gensim/test/test_matutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_dirichlet_expectation(self):

def manual_unitvec(vec):
# manual unit vector calculation for UnitvecTestCase
vec = vec.astype(np.float)
vec = vec.astype(float)
if sparse.issparse(vec):
vec_sum_of_squares = vec.multiply(vec)
unit = 1. / np.sqrt(vec_sum_of_squares.sum())
Expand Down
2 changes: 1 addition & 1 deletion gensim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from __future__ import with_statement
from contextlib import contextmanager
import collections
import collections.abc as collections
import logging
import warnings
import numbers
Expand Down