From 51dba8281edacf075f37809ff551b0b5e0290cae Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Mon, 19 Aug 2024 15:27:31 +0200 Subject: [PATCH 1/2] Remove deprecationWarnings on import pyalex and remove Venues --- README.md | 2 +- pyalex/__init__.py | 4 ---- pyalex/api.py | 49 ++++++++++++++-------------------------------- pyproject.toml | 2 +- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 1262333..ea70093 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Works()["W2741809807"]["open_access"] {'is_oa': True, 'oa_status': 'gold', 'oa_url': 'https://doi.org/10.7717/peerj.4375'} ``` -The previous works also for Authors, Venues, Institutions, Concepts and Topics +The previous works also for Authors, Sources, Institutions, Concepts and Topics ```python Authors()["A2887243803"] diff --git a/pyalex/__init__.py b/pyalex/__init__.py index 16b1f17..7401ae6 100644 --- a/pyalex/__init__.py +++ b/pyalex/__init__.py @@ -27,8 +27,6 @@ from pyalex.api import Subfields from pyalex.api import Topic from pyalex.api import Topics -from pyalex.api import Venue -from pyalex.api import Venues from pyalex.api import Work from pyalex.api import Works from pyalex.api import autocomplete @@ -46,8 +44,6 @@ "Funders", "Publishers", "Publisher", - "Venues", - "Venue", "Institutions", "Institution", "Concepts", diff --git a/pyalex/api.py b/pyalex/api.py index df1a1d4..17f9d96 100644 --- a/pyalex/api.py +++ b/pyalex/api.py @@ -483,46 +483,27 @@ def __getitem__(self, key): ) -def Venue(*args, **kwargs): # deprecated - # warn about deprecation - warnings.warn( - "Venue is deprecated. Use Sources instead.", - DeprecationWarning, - stacklevel=2, - ) - - return Source(*args, **kwargs) - - -def Venues(*args, **kwargs): # deprecated - # warn about deprecation - warnings.warn( - "Venues is deprecated. Use Sources instead.", - DeprecationWarning, - stacklevel=2, - ) - - return Sources(*args, **kwargs) - - class Concept(OpenAlexEntity): - # warn about deprecation - warnings.warn( - "Concept is deprecated by OpenAlex and replaced by topics.", - DeprecationWarning, - stacklevel=2, - ) + def __init__(self, *args, **kwargs): + warnings.warn( + "Concept is deprecated by OpenAlex and replaced by topics.", + DeprecationWarning, + stacklevel=2, + ) + super().__init__(*args, **kwargs) class Concepts(BaseOpenAlex): - # warn about deprecation - warnings.warn( - "Concepts is deprecated by OpenAlex and replaced by topics.", - DeprecationWarning, - stacklevel=2, - ) resource_class = Concept + def __init__(self, *args, **kwargs): + warnings.warn( + "Concepts is deprecated by OpenAlex and replaced by topics.", + DeprecationWarning, + stacklevel=2, + ) + super().__init__(*args, **kwargs) + def autocomplete(s): """autocomplete with any type of entity""" diff --git a/pyproject.toml b/pyproject.toml index 752bd70..5ff1e47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,4 +41,4 @@ force-single-line = true [tool.pytest.ini_options] pythonpath = ["."] -addopts = "-v" +addopts = "-v -W error" From 391de39ad6ab666ad22303d31a2d876d95eb84c3 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Mon, 19 Aug 2024 15:34:08 +0200 Subject: [PATCH 2/2] Fix test for deprecation warning for concepts --- tests/test_pyalex.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_pyalex.py b/tests/test_pyalex.py index 83e5f6a..a02b32e 100644 --- a/tests/test_pyalex.py +++ b/tests/test_pyalex.py @@ -37,8 +37,6 @@ def test_config(): def test_meta_entities(): _, m = Authors().get(return_meta=True) assert "count" in m - _, m = Concepts().get(return_meta=True) - assert "count" in m _, m = Institutions().get(return_meta=True) assert "count" in m _, m = Sources().get(return_meta=True) @@ -57,6 +55,12 @@ def test_meta_entities(): assert "count" in m +@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning") +def test_meta_entities_deprecated(): + _, m = Concepts().get(return_meta=True) + assert "count" in m + + def test_works_params(): assert len(Works(params={"filter": {"publication_year": "2020"}}).get()) == 25