Skip to content

Commit

Permalink
Initialize self.cfs in Dictionary.compatify method (#2618)
Browse files Browse the repository at this point in the history
* Fix for #2574

* Fix for #2574
  • Loading branch information
SanthoshBala18 authored and mpenkov committed Jan 5, 2020
1 parent 74a375d commit f022028
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions gensim/corpora/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ def compactify(self):
self.token2id = {token: idmap[tokenid] for token, tokenid in iteritems(self.token2id)}
self.id2token = {}
self.dfs = {idmap[tokenid]: freq for tokenid, freq in iteritems(self.dfs)}
self.cfs = {idmap[tokenid]: freq for tokenid, freq in iteritems(self.cfs)}

def save_as_text(self, fname, sort_by_word=True):
"""Save :class:`~gensim.corpora.dictionary.Dictionary` to a text file.
Expand Down
6 changes: 4 additions & 2 deletions gensim/test/test_corpora_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ def testMerge(self):
def testFilter(self):
d = Dictionary(self.texts)
d.filter_extremes(no_below=2, no_above=1.0, keep_n=4)
expected = {0: 3, 1: 3, 2: 3, 3: 3}
self.assertEqual(d.dfs, expected)
dfs_expected = {0: 3, 1: 3, 2: 3, 3: 3}
cfs_expected = {0: 4, 1: 3, 2: 3, 3: 3}
self.assertEqual(d.dfs, dfs_expected)
self.assertEqual(d.cfs, cfs_expected)

def testFilterKeepTokens_keepTokens(self):
# provide keep_tokens argument, keep the tokens given
Expand Down

0 comments on commit f022028

Please sign in to comment.