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

Return error when paging with cursor method while using sample #44

Merged
merged 2 commits into from
Jul 16, 2024

Conversation

PeterLombaers
Copy link
Contributor

@PeterLombaers PeterLombaers commented Jul 16, 2024

When sampling records from OpenAlex you must use basic paging instead of cursor paging (see the OpenAlex docs).

Currently pyalex has cursor paging as the default method. If you combine sample with paginate it will present the first page and then silently stop paging, without any error. For example, the following test fails:

def test_paging_with_sample():
    p = Authors().sample(26).paginate(per_page=25)
    assert sum(len(page) for page in p) == 26

Pyalex will choose the default cursor method, and only return the first page. So the left side of the assert statement will be 25.

In this pull request I make pyalex raise a ValueError when trying to use cursor pagination with sampling. If you want, I can also change it so that the default method for pagination becomes page in case of sampling, but I thought it was better to be explicit and just let the user know that their combination is not allowed. Let me know if you think differently and I'll update my changes!

@J535D165 J535D165 merged commit 9673ee1 into J535D165:main Jul 16, 2024
4 checks passed
@J535D165
Copy link
Owner

Nice catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants