Skip to content

Commit

Permalink
Return error when paging with cursor method while using sample (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterLombaers authored Jul 16, 2024
1 parent 6036385 commit 9673ee1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyalex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/test_paging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

import pyalex
from pyalex import Authors
from pyalex.api import Paginator
Expand Down Expand Up @@ -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")

0 comments on commit 9673ee1

Please sign in to comment.