diff --git a/gensim/corpora/dictionary.py b/gensim/corpora/dictionary.py index 229d28d2c9..2ba296b115 100644 --- a/gensim/corpora/dictionary.py +++ b/gensim/corpora/dictionary.py @@ -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. diff --git a/gensim/test/test_corpora_dictionary.py b/gensim/test/test_corpora_dictionary.py index cca9993952..29338ad45e 100644 --- a/gensim/test/test_corpora_dictionary.py +++ b/gensim/test/test_corpora_dictionary.py @@ -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