Repository navigation
[Data] Add a data-pr skill and review rules for code and tests - #67919
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
There was a problem hiding this comment.
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.** |
There was a problem hiding this comment.
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.
| - **Return a dataclass or `NamedTuple`, not a bare tuple.** | |
| - **Return a dataclass or NamedTuple instead of a bare tuple for public or complex interfaces.** |
| `[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. |
There was a problem hiding this comment.
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.
| <!-- 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.** |
There was a problem hiding this comment.
Not sure what this means?
|
|
||
| ## Design | ||
| - **Fix at the choke point.** | ||
| - **A new field on a shared type reaches everything that builds one.** |
There was a problem hiding this comment.
Super vague. Need an example
| ## Design | ||
| - **Fix at the choke point.** | ||
| - **A new field on a shared type reaches everything that builds one.** | ||
| - **Write each piece of logic once.** |
There was a problem hiding this comment.
Just say that the design should be modular and extensible and avoid repetition of logic
| - **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.** |
There was a problem hiding this comment.
Not sure what this means?
| - **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.** |
There was a problem hiding this comment.
Again unclear what this means
| - **Size work by its peak memory,** not bytes on disk or item counts. | ||
| - **Do I/O in a few large reads, once.** |
There was a problem hiding this comment.
leave these out.
| large end. | ||
|
|
||
| ## Errors and compatibility | ||
| - **One bad input fails only its own work.** |
There was a problem hiding this comment.
Say that errors should be isolated and verifiable
|
|
||
| ## Errors and compatibility | ||
| - **One bad input fails only its own work.** | ||
| - **Retry only transient errors, and nothing that already retries.** |
There was a problem hiding this comment.
avoid a retry storm
| - "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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
We should use claude code review for this one. Drafted here: #67928
There was a problem hiding this comment.
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]>
## 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]>
Summary
Adds a
data-prClaude Code skill and Ray Data review rules underpython/ray/data/.claude/, so contributors using Claude Code catch the feedbackwe 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 anedge-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 authorapproves.
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 itsfix is reverted.
Rules files load whenever Claude Code edits a matching file. No runtime code
changes.
Testing
pre-commit run --fileson the three files passed. The skill hasn't been runend 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