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

Initialize self.cfs in Dictionary.compatify method #2618

Merged
merged 2 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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