diff --git a/pyalex/api.py b/pyalex/api.py index 2cb3149..df1a1d4 100644 --- a/pyalex/api.py +++ b/pyalex/api.py @@ -307,6 +307,8 @@ def get(self, return_meta=False, page=None, per_page=None, cursor=None): def paginate(self, method="cursor", page=1, per_page=None, cursor="*", n_max=10000): if method == "cursor": + if self.params.get("sample"): + raise ValueError("method should be 'page' when using sample") value = cursor elif method == "page": value = page diff --git a/tests/test_paging.py b/tests/test_paging.py index 80963c9..944053b 100644 --- a/tests/test_paging.py +++ b/tests/test_paging.py @@ -1,3 +1,5 @@ +import pytest + import pyalex from pyalex import Authors from pyalex.api import Paginator @@ -95,3 +97,8 @@ def test_cursor_paging_n_max_none(): ) sum(len(page) for page in p) + + +def test_paging_with_sample(): + with pytest.raises(ValueError): + Authors().sample(1).paginate(method="cursor")