fix(freshcore): fall back when native casts create columns the kernels mishandle - #422
Merged
Merged
Conversation
…s mishandle The adapter's input checks only see the input dtypes, but FreshCore's native fix_dtypes stage casts text columns before imputation and outlier detection run. Two casts reach known kernel gaps: - "yes"/"no" text with missing values becomes a boolean column, which the native imputer skips, so mode/auto imputation leaves it unfilled while pandas fills it. - numeric text holding "inf" becomes a float column holding inf, which the native fences do not exclude, so zscore/iqr flag nothing while pandas drops inf before fencing. After the native run, the adapter now checks the returned column dtypes for text columns cast to bool or float. When a cast column hits either gap, it records a fallback naming the column (step "impute" or "outliers") and reruns on pandas. Under fallback_policy="error" it raises FallbackError. The scan covers only cast columns and runs only when impute or outliers is set, so other frames stay native.
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
FreshData benchmark report —
|
| fixture | n_rows | n_cols | p50 s | p95 s | peak MB | repair % | false-repair % | preserve % | trust | monotonic | export % |
|---|
Authored-code reduction (Metric 6)
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.
Summary
FreshCore could return results that differ from pandas when its own
fix_dtypesstage turned a text column into a column its kernels mishandle. The adapter now detects these casts in the native result and reruns the run on the pandas reference path, recording a fallback event that names the column.Root cause
FreshCoreEngine._unsupported_reasonchecks only the input frame's dtypes. The native module casts text columns (casts.rs) before imputation and outlier detection run (python.rs), which opens two kernel gaps:try_boolturns"yes"/"no"text into aBoolcolumn.missing.rsskipsBoolcolumns, so underimpute="mode"/"auto"their missing values stay unfilled. pandas fills them.parse_numericaccepts"inf".outliers.rsfilters only NaN, so zscore/iqr fences on that column are undefined and nothing is flagged. pandas drops±infbefore computing fences.Behaviour change
engine="freshcore", it reruns on pandas and records a fallback event naming the column in two cases:fix_dtypescasts a text column to boolean, the column still has missing values, andimputeis"mode"or"auto"(fallback_step="impute").fix_dtypescasts a text column holding±infto float and outliers are enabled (fallback_step="outliers").fallback_policy="warn"warns;"error"raisesFallbackError.fd.plan()checks only the input, so it can't predict these fallbacks;docs/freshcore.mdsays so.docs/fallback-matrix.mdanddocs/freshcore.mdlist the new fallbacks.Default-output changes
None. The default
strategy="balanced"already routes everyengine="freshcore"run to pandas, and the defaultsimpute=None/outliers=Noneskip the new check. Newfallback_eventsentries appear only when all of these hold:engine="freshcore"withstrategy="conservative"impute="mode"/"auto", or outliers enabledThere are no new
backend_differencesentries.Tests
tests/test_execution/test_freshcore_engine.pytests the fallback decision with a fake module, so the native build isn't needed."error"raises.tests/test_execution/test_freshcore_native_parity.pyis skipped unlessfreshdata_freshcoreis built."error"raises.Verification
ruff check .andmypy src/freshdata: clean.pytest -m "not online and not large": Python 3.12, 6269 passed; Python 3.9, 6240 passed.maturin develop),pytest tests/test_execution -k freshcoregives 127 passed, 1 skipped.impute="mode":[T,F,<NA>,T,T]→[T,F,T,T,T], same as pandas."inf"+ zscore/iqr: nothing flagged → flags match pandas.