Skip to content

[Fix] Use seeded random.Random for dataset shuffling#1243

Open
pcabriada wants to merge 4 commits intomodelscope:mainfrom
pcabriada:bugfix/fix-shuffle-python312
Open

[Fix] Use seeded random.Random for dataset shuffling#1243
pcabriada wants to merge 4 commits intomodelscope:mainfrom
pcabriada:bugfix/fix-shuffle-python312

Conversation

@pcabriada
Copy link

Python 3.12 removed the deprecated second argument from random.shuffle(). LocalDataLoader.load() and DictDataLoader.load() both passed self.seed as the second argument, causing TypeError on Python 3.12+.

Replace with random.Random(seed).shuffle(dataset) when a seed is provided, falling back to unseeded random.shuffle() when seed is None.

RemoteDataLoader is unaffected (uses HuggingFace Dataset.shuffle(seed=...)).

Added tests/test_loader_shuffle.py covering seeded shuffle, unseeded shuffle, reproducibility, and a guard confirming the original call fails on 3.12+.

…mpat)

Python 3.12 removed the deprecated second argument from random.shuffle().
LocalDataLoader.load() and DictDataLoader.load() both passed self.seed as
the second argument, causing TypeError on Python 3.12+.

Replace with random.Random(seed).shuffle(dataset) when a seed is provided,
falling back to unseeded random.shuffle() when seed is None.

RemoteDataLoader is unaffected (uses HuggingFace Dataset.shuffle(seed=...)).

Added tests/test_loader_shuffle.py covering seeded shuffle, unseeded shuffle,
reproducibility, and a guard confirming the original call fails on 3.12+.

Made-with: Cursor
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a compatibility issue with Python 3.12 by updating how datasets are shuffled within LocalDataLoader and DictDataLoader. The changes ensure that dataset shuffling functions correctly and reproducibly, whether a seed is provided or not, aligning with Python's updated random module behavior. Comprehensive tests have been added to validate the fix and prevent future regressions.

Highlights

  • Python 3.12 Compatibility: Adapted LocalDataLoader and DictDataLoader to correctly handle dataset shuffling with Python 3.12, which removed the deprecated random.shuffle(sequence, random_function) signature.
  • Seeded Randomness: Implemented the use of random.Random(seed).shuffle(dataset) for reproducible shuffling when a seed is provided, falling back to random.shuffle(dataset) for unseeded shuffling.
  • New Test Coverage: Introduced a new test file (tests/test_loader_shuffle.py) to cover seeded and unseeded shuffling, reproducibility, and to confirm the original problematic call fails on Python 3.12+.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request correctly fixes a TypeError when shuffling datasets on Python 3.11+ by using random.Random(seed).shuffle() for seeded shuffles. The changes in evalscope/api/dataset/loader.py are correct. The new test file tests/test_loader_shuffle.py provides good coverage for the fix, including checks for reproducibility. I've made a couple of suggestions for improvement: one to refactor duplicated code into a helper function for better maintainability, and another to correct the Python version check in a test case.

pcabriada and others added 3 commits March 20, 2026 15:56
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Address reviewer feedback: extract the shuffle logic shared by
LocalDataLoader.load() and DictDataLoader.load() into a private
module-level helper function.

Made-with: Cursor
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.

1 participant