Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #80 from coreofscience/fix-missing-fields-raise
Browse files Browse the repository at this point in the history
Do not take into account articles with missing fields
  • Loading branch information
odarbelaeze authored Aug 24, 2020
2 parents e9b06cc + 4b962bb commit ff6cd97
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "Translates isi web of knowledge files into python objects.",
"license": "MIT",
"title": "coreofscience/python-wostools",
"version": "v2.0.6",
"version": "v2.0.7",
"upload_type": "software",
"publication_date": "2018-08-13",
"creators": [
Expand All @@ -25,7 +25,7 @@
"related_identifiers": [
{
"scheme": "url",
"identifier": "https://github.com/coreofscience/python-wostools/tree/v2.0.6",
"identifier": "https://github.com/coreofscience/python-wostools/tree/v2.0.7",
"relation": "isSupplementTo"
},
{
Expand Down
6 changes: 5 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# History

## 2.0.5 (2020-08-21)
## 2.0.7 (2020-08-23)

- Remove from the collection those documents whose label is unknow or conflictive.

## 2.0.6 (2020-08-21)

- Accomodate for unknown fields in ISI WOS files.

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/coreofscience/python-wostools",
version="2.0.6",
version="2.0.7",
zip_safe=False,
long_description_content_type="text/markdown",
)
4 changes: 2 additions & 2 deletions tests/test_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pytest_bdd import given, parsers, scenarios, then, when

from wostools.article import Article
from wostools.exceptions import InvalidIsiLine, InvalidReference
from wostools.exceptions import InvalidIsiLine, InvalidReference, MissingLabelFields

from wostools._testutils import Context

Expand Down Expand Up @@ -286,7 +286,7 @@ def no_error_computing_label(label_context: Context[str]):
@then("There's an error computing the label")
def error_computing_label(label_context: Context[str]):
with label_context.assert_error() as error:
assert isinstance(error, ValueError)
assert isinstance(error, MissingLabelFields)


@then(parsers.parse("the article matches the {field:w} of the other"))
Expand Down
2 changes: 1 addition & 1 deletion wostools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Core of Science"""
__email__ = "[email protected]"
__version__ = "2.0.6"
__version__ = "2.0.7"

from wostools.article import Article
from wostools.lazy import LazyCollection
Expand Down
20 changes: 11 additions & 9 deletions wostools/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import itertools
import logging
from contextlib import suppress
from typing import Dict, Iterable, Iterator, Tuple

from wostools.article import Article
from wostools.base import BaseCollection
from wostools.exceptions import InvalidReference
from wostools.exceptions import InvalidReference, MissingLabelFields

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -40,14 +41,15 @@ def _preheat(self):
if key == self._cache_key:
return
for article in self._articles():
self._add_article(article)
for reference in article.references:
try:
self._add_article(Article.from_isi_citation(reference))
except InvalidReference:
logger.info(
f"Ignoring malformed reference '{reference}' from '{article.label}'"
)
with suppress(MissingLabelFields):
self._add_article(article)
for reference in article.references:
try:
self._add_article(Article.from_isi_citation(reference))
except InvalidReference:
logger.info(
f"Ignoring malformed reference '{reference}' from '{article.label}'"
)
self._cache_key = key

def __iter__(self) -> Iterator[Article]:
Expand Down
8 changes: 5 additions & 3 deletions wostools/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import itertools
import logging
from contextlib import suppress
from typing import Iterable, Tuple

from wostools.article import Article
from wostools.base import BaseCollection
from wostools.exceptions import InvalidReference
from wostools.exceptions import InvalidReference, MissingLabelFields

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -37,8 +38,9 @@ def _article_texts(self):
yield article_text

def _articles(self) -> Iterable[Article]:
for article_text in self._article_texts:
yield Article.from_isi_text(article_text)
with suppress(MissingLabelFields):
for article_text in self._article_texts:
yield Article.from_isi_text(article_text)

@property
def authors(self) -> Iterable[str]:
Expand Down

0 comments on commit ff6cd97

Please sign in to comment.