Skip to content

Commit 0ba67d7

Browse files
deepyamanclaude
andcommitted
Fix failure case handling to match original behavior
Convert failure rows to dict records format before reshaping, so each failing row becomes a single failure case (a dict of column values) rather than having each cell become a separate failure case. This matches the original run_check behavior and ensures n_failure_cases correctly limits the number of failure cases reported. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Deepyaman Datta <deepyaman.datta@utexas.edu>
1 parent 89ba452 commit 0ba67d7

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

pandera/backends/ibis/base.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,16 @@ def _extract_check_results(
198198
:param schema: The schema being validated against.
199199
:returns: List of CoreCheckResult objects.
200200
"""
201+
from pandera.api.pandas.types import is_table
202+
201203
results = []
202204

205+
# Get original column names (columns without check output suffix)
206+
original_cols = [
207+
c for c in wide_executed.columns
208+
if not c.endswith(CHECK_OUTPUT_SUFFIX)
209+
]
210+
203211
for check_index, check in checks_applied:
204212
# Find check columns by prefix pattern: {check_index}_{col}{CHECK_OUTPUT_SUFFIX}
205213
prefix = f"{check_index}_"
@@ -234,15 +242,22 @@ def _extract_check_results(
234242
else:
235243
# Extract failure cases: rows where any check column is False
236244
failure_mask = ~wide_executed[check_cols].all(axis=1)
237-
original_cols = [
238-
c for c in wide_executed.columns
239-
if not c.endswith(CHECK_OUTPUT_SUFFIX)
240-
]
241-
failure_cases = wide_executed.loc[failure_mask, original_cols]
245+
failure_rows = wide_executed.loc[failure_mask, original_cols]
242246

243-
# Apply n_failure_cases limit
247+
# Apply n_failure_cases limit (limiting rows before conversion)
244248
if check.n_failure_cases is not None:
245-
failure_cases = failure_cases.head(check.n_failure_cases)
249+
failure_rows = failure_rows.head(check.n_failure_cases)
250+
251+
# Convert to dict records format, matching original run_check behavior
252+
# Each row becomes a single failure case (a dict of column values)
253+
if is_table(failure_rows):
254+
failure_cases = (
255+
pd.Series(failure_rows.to_dict("records"))
256+
.rename("failure_case")
257+
.to_frame()
258+
)
259+
else:
260+
failure_cases = failure_rows
246261

247262
failure_cases = reshape_failure_cases(
248263
failure_cases, check.ignore_na

0 commit comments

Comments
 (0)