Fix absolute schema_path handling in Dataset.to_file#6143
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This keeps
Dataset.to_file()from serializing machine-local absolute schema paths when the schema file is next to the dataset file.What Problem This Solves
When
Dataset.to_file()receives an absoluteschema_pathin the same directory as the dataset file, it currently compares the schema path against the dataset file path itself:Sibling files are not relative to each other, so that branch is skipped and the generated dataset stores an absolute
$schemareference instead of a portable sibling reference.Before this change, a local reproduction wrote a machine-local path like:
That makes checked-in datasets less portable and can expose local machine paths.
Change
schema_pathagainstpath.parent, the dataset directory.$schemareference relative to that directory when possible.Evidence
After this change, the same reproduction writes a portable sibling reference:
The schema file is still written to the requested absolute path; only the serialized reference changes.
Validation
uv run pytest tests/evals/test_dataset.py::test_serialization_to_json tests/evals/test_dataset.py::test_serialization_to_json_with_absolute_schema_pathuv run ruff check pydantic_evals/pydantic_evals/dataset.py tests/evals/test_dataset.pyuv run ruff format --check pydantic_evals/pydantic_evals/dataset.py tests/evals/test_dataset.pygit diff --checkNo issue; this is a narrow regression fix for an existing code path.
Checklist