Skip to content

Commit

Permalink
Handle optional parameters without implicit bool cast (#3502)
Browse files Browse the repository at this point in the history
* Handle optional parameters without implicit bool cast

* dummy commit to trigger CI

---------

Co-authored-by: Michael Penkov <m@penkov.dev>
  • Loading branch information
nk-fouque and mpenkov authored Jun 11, 2024
1 parent caeca0c commit c95bdb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ BibTeX entry:
[OpenBLAS]: https://xianyi.github.io/OpenBLAS/
[source tar.gz]: https://pypi.org/project/gensim/
[documentation]: https://radimrehurek.com/gensim/#install

12 changes: 6 additions & 6 deletions gensim/models/tfidfmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,16 @@ def __init__(self, corpus=None, id2word=None, dictionary=None, wlocal=utils.iden
self.pivot = pivot
self.eps = 1e-12

if smartirs:
if smartirs is not None:
n_tf, n_df, n_n = self.smartirs
self.wlocal = partial(smartirs_wlocal, local_scheme=n_tf)
self.wglobal = partial(smartirs_wglobal, global_scheme=n_df)

if dictionary:
if dictionary is not None:
# user supplied a Dictionary object, which already contains all the
# statistics we need to construct the IDF mapping. we can skip the
# step that goes through the corpus (= an optimization).
if corpus:
if corpus is not None:
logger.warning(
"constructor received both corpus and explicit inverse document frequencies; ignoring the corpus"
)
Expand All @@ -378,17 +378,17 @@ def __init__(self, corpus=None, id2word=None, dictionary=None, wlocal=utils.iden
self.dfs = dictionary.dfs.copy()
self.term_lens = {termid: len(term) for termid, term in dictionary.items()}
self.idfs = precompute_idfs(self.wglobal, self.dfs, self.num_docs)
if not id2word:
if id2word is None:
self.id2word = dictionary
elif corpus:
elif corpus is not None:
self.initialize(corpus)
else:
# NOTE: everything is left uninitialized; presumably the model will
# be initialized in some other way
pass

# If smartirs is not None, override pivot and normalize
if not smartirs:
if smartirs is None:
return
if self.pivot is not None:
if n_n in 'ub':
Expand Down

0 comments on commit c95bdb4

Please sign in to comment.