Conversation
Preprocessor.transform built the pandas DataFrame with a fresh RangeIndex.
scikit-learn's set_output wrapper keeps the index of a returned DataFrame,
so the input index was lost: ColumnTransformer(...).set_output("pandas")
raised on a non-default index and FeatureUnion returned 2n NaN-padded rows.
Pass X's index through to_dataframe_output (new keyword-only `index`).
Closes #60
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.
Closes #60
Problem
With
set_output(transform="pandas")(orsklearn.set_config(transform_output="pandas")),Preprocessor.transformreturned a DataFrame with a freshRangeIndexinstead of the input's index. Because the method already returns a DataFrame, scikit-learn'sset_outputwrapper keeps that DataFrame's index rather than restoring the input's. As a result:ColumnTransformer([... Preprocessor ...]).set_output(transform="pandas")raisedValueError: Concatenating DataFrames ... Pandas Indexes that do not matchwhenever the index was not0..n-1, e.g. aftertrain_test_split.FeatureUnion([... Preprocessor ...]).set_output(transform="pandas")silently returned2nrows padded with NaN.Change
pretab/compose/output.py:to_dataframe_outputtakes a new keyword-onlyindex=Noneargument, used for the pandas container. Polars has no index and is unchanged.pretab/preprocessor.py:transformpassesX.indexthrough.NumPy and dict inputs still get a default
RangeIndex, as before.Tests
Regression tests added. All four fail on
mainand pass with this change:tests/integration/test_output_format.py:transform/fit_transformkeep a non-default index;ColumnTransformercomposition;FeatureUnioncomposition (n rows, no NaN).tests/compose/test_output.py: unit test forto_dataframe_output(..., index=...).Full suite: 1442 passed, 59 skipped, 7 xfailed.
ruff checkandruff format --checkare clean.