Skip to content

Conversation

@maitry63
Copy link

This PR updates the PyDataset class docstring inside keras/src/trainers/data_adapters/py_dataset_adapter.py to include the documentation for the `shuffle´ argument.

Context

Addresses issue #20142.

Notes

  • Adds clarification about `shuffle´ default behavior (False).
  • Keeps the existing example intact, adding only the `shuffle´ usage line.
  • No functional code changes.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @maitry63, 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 enhances the clarity and completeness of the PyDataset class documentation within Keras. It specifically addresses the shuffle argument, providing a comprehensive explanation of its functionality and default state. Additionally, the accompanying example has been updated to illustrate the correct implementation of data shuffling at the end of each epoch, improving user understanding and guidance.

Highlights

  • Documentation Update: The docstring for the PyDataset class has been updated to include detailed information about the shuffle argument, its default behavior, and how it integrates with model.fit().
  • Example Enhancement: The CIFAR10PyDataset example now demonstrates how to properly implement shuffling by adding a shuffle parameter to its __init__ and an on_epoch_end method to handle epoch-end shuffling.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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

This pull request updates the documentation for the PyDataset class to clarify the behavior of the shuffle argument. The changes include adding documentation for the argument in the class docstring, providing a note on its usage, and updating the example to demonstrate shuffling. My review focuses on improving the clarity and correctness of the new documentation and example code. I've pointed out some grammatical and formatting issues in the docstring, a critical typo and a style issue in the example's __init__ method, and a logical flaw in the example's shuffling implementation which makes it non-functional.

Comment on lines 43 to 48
shuffle: Whether to shuffle the sample ordering at the end of
each epoch.This argument passed to `model.fit()`. when
`model.fit(.., shuffle=True)`, the training loop
automatically calls `on_epoch_end()` at each epoch
boundary, allowing datasets to implement custom
shuffling logic. Defaults to False.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There are a few grammatical and formatting issues in the docstring for the shuffle argument. It would be clearer with some corrections for spacing, sentence structure, and consistent code formatting.

Suggested change
shuffle: Whether to shuffle the sample ordering at the end of
each epoch.This argument passed to `model.fit()`. when
`model.fit(.., shuffle=True)`, the training loop
automatically calls `on_epoch_end()` at each epoch
boundary, allowing datasets to implement custom
shuffling logic. Defaults to False.
shuffle: Whether to shuffle the sample ordering at the end of
each epoch. This argument is passed to `model.fit()`. When
`model.fit(..., shuffle=True)`, the training loop
automatically calls `on_epoch_end()` at each epoch
boundary, allowing datasets to implement custom
shuffling logic. Defaults to `False`.

maitry63 and others added 2 commits November 13, 2025 21:57
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.48%. Comparing base (bfde12b) to head (54cae65).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21847      +/-   ##
==========================================
- Coverage   82.66%   82.48%   -0.19%     
==========================================
  Files         577      577              
  Lines       59506    59507       +1     
  Branches     9330     9331       +1     
==========================================
- Hits        49193    49085     -108     
- Misses       7910     8010     +100     
- Partials     2403     2412       +9     
Flag Coverage Δ
keras 82.30% <ø> (-0.19%) ⬇️
keras-jax 62.90% <ø> (-0.42%) ⬇️
keras-numpy 57.55% <ø> (+<0.01%) ⬆️
keras-openvino 34.35% <ø> (+<0.01%) ⬆️
keras-tensorflow 64.12% <ø> (+<0.01%) ⬆️
keras-torch 63.61% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

self.x, self.y = x_set, y_set
self.batch_size = batch_size
self.shuffle = shuffle
self.indices = np.arange(len(self.x))
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the example, also do np.random.shuffle(self.indices) here when shuffle is True, since the best practice when shuffling is to do it for every epoch, not just epoch >= 1

your dataset. Defaults to 10.
shuffle: Whether to shuffle the sample ordering at the end of
each epoch. This argument is passed to `model.fit()`. When
`model.fit(..., shuffle=True)`, the training loop
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add verb: "When calling"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants