Repository navigation
fix(preprocessor): re-infer object array columns at fit - #156
Merged
Merged
Conversation
to_dataframe wrapped an object ndarray (df.to_numpy() of mixed data, or the output of SimpleImputer on a mixed frame) with every column as object, so fit detected numeric columns as categorical and one-hot or ordinal encoded each distinct number. transform already called infer_objects() for arrays, so fit and transform disagreed. to_dataframe now re-infers the columns of input without labels, which covers fit, the feature-group validation and the task preflight as well as transform; _align_input no longer repeats it. Labelled frames keep their dtypes. Fixes #155
This was referenced Nov 29, 2026
mkumar73
approved these changes
Nov 30, 2026
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.
Fixes #155.
Preprocessor.fiton an object ndarray detected every column as categorical, so a numeric column ofdf.to_numpy()(or of aSimpleImputer(strategy="most_frequent")output on mixed data) was one-hot or ordinal encoded with one category per distinct value.transformalready re-inferred those columns, so fit and transform disagreed.Root cause
to_dataframe(pretab/compose/feature_detection.py) wrapped an array as-is, keeping every column of an object array asobject.transformcalledinfer_objects()in_align_input, butfit, the feature-group validation infitand_preflight_task_targetdid not.Fix
to_dataframecallsinfer_objects()when it wraps input without column labels (an array or a list of rows). Every entry point goes through it, sofit, the group validation, the task preflight andtransformsee the same dtypes._align_input(pretab/preprocessor.py) no longer repeats the call.Behaviour changes
fit, with the integercat_cutoffheuristic applied as for a DataFrame. Before, it was always categorical. A preprocessor fitted on an object array therefore gets a different (much smaller) layout and fingerprint than onmain.Documentation
to_dataframedocstring and thePreprocessor.fitXparameter: the numeric columns of an object array are re-inferred before the column types are detected.docs/core_concepts/configuration.md(array input): object-array columns are re-inferred, withdf.to_numpy()andSimpleImputeras examples.transformdocstring now hold as written.Tests
tests/compose/test_feature_detection.py::test_to_dataframe_reinfers_the_columns_of_an_object_array: fails onmain, passes here.test_to_dataframe_keeps_the_dtypes_of_a_labelled_frameis a guard that passes on both.tests/integration/test_preprocessor.py::test_object_array_fit_detects_the_column_types_of_the_frame: same types, widths and output as the DataFrame fit. Fails onmain, passes here.tests/integration/test_preprocessor.py::test_imputed_mixed_frame_keeps_its_numerical_columns:SimpleImputer→Preprocessorpipeline. Fails onmain, passes here.tests/core/test_cross_fitted.py::test_fit_transform_keeps_strings_left_unchanged: this test relied on the float column of its object array being misdetected as categorical and passed through bycategorical_method=None. It now passes the float column through withnumerical_method="none", scaling="none"and asserts the detected types. Its purpose, strings surviving cross-fitting unchanged in an object output, is unchanged.Reproduction
The script from #155 on this branch:
Checks
just test: 4680 passed, 59 skipped, 7 xfailed; coverage 95.71% (gate 90%).scripts/quickstart.pypasses.just docs: strict build succeeds.just check: all pre-commit and pre-push hooks pass (file hygiene, ruff format, ruff lint, prettier, pyright with 0 errors).pretab.compose.feature_detectionand the facade; no import direction changes.Merge notes
main.pretab/compose/feature_detection.py(detect_column_types, a different function). Git merges the two branches cleanly.