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

[BUG] - Fix ArticlesAll for empty collection #95

Merged
merged 1 commit into from
Aug 30, 2024
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
18 changes: 12 additions & 6 deletions lisc/data/articles_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,18 @@ def create_summary(self):

self.summary['label'] = self.label
self.summary['n_articles'] = str(self.n_articles)
self.summary['top_author_name'] = ' '.join(self.authors.most_common()[0][0])
self.summary['top_author_count'] = str(self.authors.most_common()[0][1])
self.summary['top_journal_name'] = self.journals.most_common()[0][0]
self.summary['top_journal_count'] = str(self.journals.most_common()[0][1])
self.summary['top_keywords'] = [freq[0] for freq in self.keywords.most_common()[0:5]]
self.summary['first_publication'] = str(min(self.years.keys()))
if self.has_data:
self.summary['top_author_name'] = ' '.join(self.authors.most_common()[0][0])
self.summary['top_author_count'] = str(self.authors.most_common()[0][1])
self.summary['top_journal_name'] = self.journals.most_common()[0][0]
self.summary['top_journal_count'] = str(self.journals.most_common()[0][1])
self.summary['top_keywords'] = [freq[0] for freq in self.keywords.most_common()[0:5]]
self.summary['first_publication'] = str(min(self.years.keys()))
else:
labels = ['top_author_name', 'top_author_count', 'top_journal_name',
'top_journal_count', 'top_keywords', 'first_publication']
for label in labels:
self.summary[label] = None


def print_summary(self):
Expand Down
28 changes: 22 additions & 6 deletions lisc/tests/data/test_articles_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ def test_articles_all(tarts_data):
data_all = ArticlesAll(tarts_data)
assert data_all

def test_articles_all_none(tarts_none):

data_all = ArticlesAll(tarts_none)
assert data_all

def test_check(tarts_all):

tarts_all.check_frequencies(data_type='words')
Expand All @@ -23,8 +18,29 @@ def test_check(tarts_all):
def test_summary(tdb, tarts_all):

tarts_all.create_summary()

assert tarts_all.summary

tarts_all.print_summary()
tarts_all.save_summary(directory=tdb)

def test_articles_all_none(tarts_none):

data_all = ArticlesAll(tarts_none)
assert data_all

data_all.check_frequencies(data_type='words')
data_all.check_frequencies(data_type='keywords')

data_all.create_summary()
assert data_all.summary

def test_articles_all_empty(tarts):

data_all = ArticlesAll(tarts)
assert not data_all.has_data

data_all.check_frequencies(data_type='words')
data_all.check_frequencies(data_type='keywords')

data_all.create_summary()
assert data_all.summary