Skip to content

[Data] Add a data-pr skill and review rules for code and tests - #67919

Merged
richardliaw merged 3 commits into
ray-project:masterfrom
AarryaSaraf:data-pr-skill
Nov 21, 2026
Merged

richardliaw merged 3 commits into
ray-project:masterfrom
AarryaSaraf:data-pr-skill

Conversation

@AarryaSaraf

Copy link
Copy Markdown
Contributor

Summary

Adds a data-pr Claude Code skill and Ray Data review rules under
python/ray/data/.claude/, so contributors using Claude Code catch the feedback
we keep repeating in review before they request one. The rules are distilled
from about 25 Ray Data reviews; a rule stays only if it came up in at least two
reviews or is a Ray requirement.

  • skills/data-pr/SKILL.md: steps for opening a Ray Data PR. They include an
    edge-case review by a fresh subagent that sees only the diff, a check of the
    diff against the rules below, lint and tests, and a description to
    python/ray/data/AGENTS.md's template. Nothing is pushed until the author
    approves.
  • rules/code_rules.md: general rules on design, naming, comments,
    performance and errors.
  • rules/test_rules.md: fewer tests by default, and each test fails when its
    fix is reverted.

Rules files load whenever Claude Code edits a matching file. No runtime code
changes.

Testing

pre-commit run --files on the three files passed. The skill hasn't been run
end to end on a PR branch yet.

Not a duplicate

No open PR adds a PR skill or review rules.

AI assistance: written with Claude Code (Claude Opus 5.5).

🤖 Generated with Claude Code

@AarryaSaraf
AarryaSaraf marked this pull request as ready for review November 7, 2026 00:28
@AarryaSaraf
AarryaSaraf requested a review from a team as a code owner November 7, 2026 00:28

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

Copy link
Copy Markdown
Contributor

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 introduces new Claude AI rules and skills for Ray Data, including general code rules, test rules, and a PR workflow skill. The review feedback suggests several improvements: relaxing the rule on returning dataclasses/NamedTuples to only apply to public or complex interfaces, allowing new test functions when extending existing ones would hurt readability, handling empty file lists in the pre-commit lint command to prevent failures, and explicitly mentioning git commit -s for commit sign-offs.

- **Every magic number is a named constant** with a comment saying why that
value.
- **No `Any` when the real type is importable.**
- **Return a dataclass or `NamedTuple`, not a bare tuple.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Forcing a dataclass or NamedTuple for every single function returning multiple values can introduce unnecessary boilerplate, especially for simple, local helper functions (e.g., returning a coordinate pair or a simple key-value pair). Consider limiting this rule to public APIs or complex internal interfaces where structured return types significantly improve readability and type safety.

Suggested change
- **Return a dataclass or `NamedTuple`, not a bare tuple.**
- **Return a dataclass or NamedTuple instead of a bare tuple for public or complex interfaces.**

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +74 to +76
`[Data]` prefix, signed as root `AGENTS.md` requires, including
`git rebase --signoff` and `git cherry-pick -s`: signing after the PR is open
means force-pushing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The repository-wide AGENTS.md requires all commits to be signed off using git commit -s. While the skill mentions git rebase --signoff and git cherry-pick -s, it should explicitly include git commit -s to guide the agent to sign off on new commits from the start, preventing the need for subsequent rebases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation data Ray Data-related issues labels Nov 7, 2026
<!-- General Ray Data code rules, distilled from code reviews. Add a rule by PR: general, one line, merged into an existing rule when one covers it. Rules for one module or format go in their own file. -->

## Design
- **Fix at the choke point.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure what this means?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed


## Design
- **Fix at the choke point.**
- **A new field on a shared type reaches everything that builds one.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Super vague. Need an example

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

## Design
- **Fix at the choke point.**
- **A new field on a shared type reaches everything that builds one.**
- **Write each piece of logic once.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just say that the design should be modular and extensible and avoid repetition of logic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

- **Fix at the choke point.**
- **A new field on a shared type reaches everything that builds one.**
- **Write each piece of logic once.**
- **Shared code never names a subclass.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure what this means?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

- **A new field on a shared type reaches everything that builds one.**
- **Write each piece of logic once.**
- **Shared code never names a subclass.**
- **Generic interfaces don't expose one library's types.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again unclear what this means

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

dropped

Comment on lines +49 to +50
- **Size work by its peak memory,** not bytes on disk or item counts.
- **Do I/O in a few large reads, once.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

leave these out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

dropped

large end.

## Errors and compatibility
- **One bad input fails only its own work.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Say that errors should be isolated and verifiable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed


## Errors and compatibility
- **One bad input fails only its own work.**
- **Retry only transient errors, and nothing that already retries.**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

avoid a retry storm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

- "python/ray/data/tests/**/*.py"
---
<!-- Ray Data test rules, distilled from code reviews. Add a rule by PR: general, one line, merged into an existing rule when one covers it. -->
Fewer tests is the default; review tests as hard as code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ideally also use pytest parameterization and avoid duplication of tests. Where possible see if you can leverage property based testing since they're more robust

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added parametrization as a rule, and property-based testing as a suggestion, since Ray doesn't depend on hypothesis yet.

@@ -0,0 +1,83 @@
---
name: data-pr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should use claude code review for this one. Drafted here: #67928

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd like both. Authors run the same checks before opening, so fewer of these reach reviewers at all, and Code Review catches the rest. To keep one list, I'll move the code and test rules into the REVIEW.md files in #67928, and this skill will check the diff against the REVIEW.md files above each changed file. This PR then only adds the skill.

…d the data-pr skill

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
richardliaw pushed a commit that referenced this pull request Nov 21, 2026
## Summary

Adds `python/ray/data/tests/AGENTS.md`, short instructions that tell
coding agents how to write Ray Data tests: shared cluster fixtures,
`DataContext` fixtures, test data, parametrize, asserts and mocks, plus
one before/after example. Recent agent-written Data PRs added 1.6× to
15× more test code than library code, much of it repeated setup: a Ray
cluster per test, a hand-set `DataContext`, field-by-field asserts.

It also adds one shared `datasource_v2` fixture to `tests/conftest.py`,
which the instructions point to. It replaces three copies of the same
fixture.

## Before

- No agent instructions say how to structure a Data test. #67919 (open)
adds rules on *which* tests to write, in
`python/ray/data/.claude/rules/`, which only Claude Code reads. #67928
(open) adds review instructions with one line on shared fixtures.
- Three copies of the V1/V2 reader fixture: `orc_reader_version` in
`test_orc.py`, `use_datasource_v2` in `test_parquet.py`, and an autouse
`datasource_v2` in `test_mcap.py`.

## After

- `python/ray/data/tests/AGENTS.md` holds the instructions. Codex,
Cursor and other agents read `AGENTS.md`;
`python/ray/data/tests/.claude/CLAUDE.md` imports it for Claude Code, as
`python/ray/data/` already does. The rules apply to new and changed
tests, not to rewriting untouched ones.
- One `datasource_v2` fixture in `tests/conftest.py`. `test_orc.py` and
`test_parquet.py` take it by name, and `test_mcap.py` applies it to
every test through `pytestmark`. Test ids (`[v1]`, `[v2]`) don't change.

No library code changes. The fixture change is a refactor: each file
collects the same tests as before.

## Subsystems

None. Tests and agent instructions only.

## Questions for reviewers

- @AarryaSaraf: this covers *how* to write tests, and your
`test_rules.md` in #67919 covers *which* tests to write. The PRs that
prompted this were written with Codex, which doesn't read
`.claude/rules/`. Would you be OK moving your test rules into this
`AGENTS.md`, here or in #67919, so every agent sees both?
- @goutamvenkat-anyscale: the fixture line in #67928's `REVIEW.md` could
link to this file.

## Additional information

### Not a duplicate

#67919 and #67928 are the only open PRs with agent rules for Data tests.
This PR covers what they don't: test structure and fixtures, in a file
that agents other than Claude Code also read.

### Testing

| Command | Result |
|---|---|
| pre-commit on the 6 changed files | Passed |
| `pytest datasource/test_mcap.py` | 67 passed, 6 skipped. The collected
test ids are identical to master's (73). |
| `pytest datasource/test_parquet.py -k "v1 or v2"` (the tests that use
the fixture) | 23 passed, 1 skipped |
| `pytest datasource/test_orc.py` | 217 passed, 6 failed: all
`test_read_orc_v2_partitioned_scan_optimizations`, which asserts the
reader's source path ends in `python/ray/data/...`. That isn't true for
the pip-installed Ray used locally, and the test doesn't use the renamed
fixture. |

Environment: Ray nightly (3eb9895) with this branch's
`python/ray/data` and `python/ray/tests` linked over it, Python 3.12.10,
pyarrow 23.0.1, pandas 2.3.3, pytest 7.4.4.

Not checked yet: that Codex and Claude Code load the new file when run
from the repository root.

### Note for open PRs

#68235 adds a test that takes `use_datasource_v2`. If it merges after
this PR, that test needs the one-word rename to `datasource_v2`.

AI assistance (Claude Code) was used to draft the instructions, the
fixture change and this description.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Abhishek Verma <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@richardliaw richardliaw added the go add ONLY when ready to merge, run all tests label Nov 21, 2026
@richardliaw
richardliaw enabled auto-merge (squash) November 21, 2026 01:05
@richardliaw
richardliaw merged commit dfe9d1e into ray-project:master Nov 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants