From a0d6d25f58de63854ac4e224245e57da74e100bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Fouqu=C3=A9?= Date: Tue, 31 Oct 2023 15:41:34 +0100 Subject: [PATCH] Handle optional parameters without implicit bool cast --- gensim/models/tfidfmodel.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gensim/models/tfidfmodel.py b/gensim/models/tfidfmodel.py index 336023bc1e..a56d7d31b1 100644 --- a/gensim/models/tfidfmodel.py +++ b/gensim/models/tfidfmodel.py @@ -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" ) @@ -378,9 +378,9 @@ 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 @@ -388,7 +388,7 @@ def __init__(self, corpus=None, id2word=None, dictionary=None, wlocal=utils.iden 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':