Repository navigation
Conversation
The ColumnTransformer stacks every block into one array, which is object
as soon as one block passes raw categories through. The pandas and
polars outputs wrapped that array as-is and the dense blocks were slices
of it, so every numeric column became object: select_dtypes("number")
found nothing and a polars mean() returned None.
When the stacked array is object, to_dataframe_output now re-infers the
pandas columns (and builds the polars frame from them), and
build_output_dict returns a dense block that holds only numbers with its
numeric dtype. Numeric outputs are unchanged.
Fixes #173
This branch has not been deployed
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 #173.
When a block passes raw categories through (
categorical_method="none"), every numeric column of the pandas output, the polars output and the dense block dictionary becameobject.select_dtypes("number")found nothing and a polarsmean()returnedNone. scikit-learn'sColumnTransformerkeeps a dtype per column.Root cause
The
ColumnTransformerstacks all blocks into one NumPy array, which isobjectas soon as one block holds strings.to_dataframe_output(pretab/compose/output.py) wrapped that array as-is, andbuild_output_dictreturned slices of it.Fix
In
pretab/compose/output.py, only when the stacked array isobject:to_dataframe_output, pandas container: the frame is passed throughinfer_objects().to_dataframe_output, polars container: the frame is built column by column from those inferred pandas columns. This needs nopyarrow, like the existing polars boundary.build_output_dict, dense blocks: a new_infer_numeric_blockreturns anobjectblock whose columns are all numeric as a numeric array. A block that still holds strings staysobject.Numeric stacked arrays (the usual case) and sparse output take the existing path unchanged.
Behaviour changes
float64), and the categories stayobject(pandas) orString(polars). Values are unchanged.return_array=Truestill returns the single stackedobjectarray, since a NumPy array has one dtype.Documentation
to_dataframe_output,build_output_dictand the new helper.docs/core_concepts/outputs_and_inspection.md(set_outputsection): each DataFrame column keeps its own dtype, as withColumnTransformer, including the dense blocks.Tests
In
tests/integration/test_output_format.py:test_pandas_output_keeps_numeric_dtypes_next_to_passed_through_categories: fails onmain, passes here.test_polars_output_keeps_numeric_dtypes_next_to_passed_through_categories: fails onmain, passes here (skipped without polars).test_dense_blocks_keep_numeric_dtypes_next_to_passed_through_categories: fails onmain, passes here.test_numeric_outputs_keep_their_dtype(default anddtype=np.float32): guard that passes on both.Reproduction
The script from #173 on this branch:
Checks
just test: 4681 passed, 59 skipped, 7 xfailed; coverage 95.72% (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.output, which already imports pandas; polars is still imported lazily. No import direction changes.Merge notes
main. Git merges this branch cleanly with every open per-issue branch (fix(binning): reject edges the soft encoding cannot use #150 to fix(validation): raise a typed error for non-finite input #172).