-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Allow FailureInfo to persist only failing rule columns #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Danila Pechenev (Danila-Pechenev)
wants to merge
1
commit into
Quantco:main
Choose a base branch
from
Danila-Pechenev:feat/failure-info-only-invalid-rules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -128,6 +128,9 @@ def details(self) -> pl.DataFrame: | |||||||||
| filters in addition to member-level rules, or when calling :meth:`Schema.filter` | ||||||||||
| with `cast=True` and dtype-casting fails for a value. | ||||||||||
| """ | ||||||||||
| if len(self._rule_columns) == 0: | ||||||||||
| return self.invalid() | ||||||||||
|
|
||||||||||
| return self._df.select( | ||||||||||
| pl.exclude(self._rule_columns), | ||||||||||
| pl.col(*self._rule_columns).replace_strict( | ||||||||||
|
|
@@ -166,24 +169,45 @@ def __len__(self) -> int: | |||||||||
|
|
||||||||||
| # ---------------------------------- PERSISTENCE --------------------------------- # | ||||||||||
|
|
||||||||||
| def write_parquet(self, file: str | Path | IO[bytes], **kwargs: Any) -> None: | ||||||||||
| def write_parquet( | ||||||||||
| self, | ||||||||||
| file: str | Path | IO[bytes], | ||||||||||
| *, | ||||||||||
| only_invalid_rules: bool = False, | ||||||||||
| **kwargs: Any, | ||||||||||
| ) -> None: | ||||||||||
| """Write the failure info to a single parquet file. | ||||||||||
|
|
||||||||||
| Writes the invalid rows along with additional boolean rule columns indicating | ||||||||||
| which validation rules failed. Unlike :meth:`invalid`, this includes columns | ||||||||||
| for each rule, where ``False`` indicates the rule failed for that row. | ||||||||||
| for each rule by default, where ``False`` indicates the rule failed for that row. | ||||||||||
|
|
||||||||||
| Setting ``only_invalid_rules`` produces a reduced, intentionally lossy | ||||||||||
| representation that omits rule columns containing only successful or unknown | ||||||||||
| outcomes. | ||||||||||
|
Comment on lines
+184
to
+187
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The argument is already documented below
Suggested change
|
||||||||||
|
|
||||||||||
| Args: | ||||||||||
| file: The file path or writable file-like object to which to write the | ||||||||||
| parquet file. | ||||||||||
| only_invalid_rules: Whether to write only rule columns containing at least | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about
Suggested change
|
||||||||||
| one validation failure. | ||||||||||
| kwargs: Additional keyword arguments passed directly to | ||||||||||
| :meth:`polars.write_parquet`. `metadata` may only be provided if it | ||||||||||
| is a dictionary. | ||||||||||
| """ | ||||||||||
| metadata = kwargs.pop("metadata", {}) or {} | ||||||||||
| self._df.write_parquet( | ||||||||||
| df = self._df | ||||||||||
| rule_columns = self._rule_columns | ||||||||||
| if only_invalid_rules: | ||||||||||
| counts = _compute_counts(df, self._rule_columns) | ||||||||||
| rule_columns = [column for column in self._rule_columns if column in counts] | ||||||||||
| df = df.drop( | ||||||||||
| column for column in self._rule_columns if column not in counts | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| df.write_parquet( | ||||||||||
| file, | ||||||||||
| metadata={**metadata, "rule_columns": json.dumps(self._rule_columns)}, | ||||||||||
| metadata={**metadata, "rule_columns": json.dumps(rule_columns)}, | ||||||||||
| **kwargs, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
|
|
||||||||||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?