skrub-data / skrub

Prepping tables for machine learning
https://skrub-data.org/
BSD 3-Clause "New" or "Revised" License
1.04k stars 91 forks source link

Support Polars dataframes across the library #769

Open Vincent-Maladiere opened 9 months ago

Vincent-Maladiere commented 9 months ago

Currently, we only partially support Polars dataframes, in most cases thanks to skrub._utils.check_input that converts dataframes into numpy arrays via sklearn.utils.validation.check_array.

Moreover, https://github.com/skrub-data/skrub/pull/733 introduced Pandas and Polars operations like aggregation and join. Note that this duplicated logic will be replaced in the mid-term by the dataframe consortium standard, as discussed in https://github.com/skrub-data/skrub/discussions/719

The following methods need to be fixed to enable Polars dataframes:

The following tests need to at least check for polars dataframe inputs:


We also need to enable polars output with our TableVectorizer, by running:

tv = TableVectorizer()
tv.set_output(transform="polars")
# X and X_transformed are Polars dataframes
X_transformed = tv.fit_transform(X)

Having Polars output in ColumnTransformer is currently under discussion at https://github.com/scikit-learn/scikit-learn/issues/25896. When made available in ColumnTransformer, this feature will also be available in TableVectorizer directly.

In the meantime, we could create a minimalistic workaround to enable Polars outputs.

This will require:

To accomplish this, I suggest to:

TheooJ commented 8 months ago

I'm working on testing for polars inputs in :

test_deduplicate.py test_fuzzy_join.py test_minhash_encoder.py test_gap_encoder.py test_similarity_encoder.py test_table_vectorizer.py test_datetime_encoder.py test_fast_hash.py test_joiner.py

jeromedockes commented 8 months ago

I wonder if instead of creating separate tests to compare polars to pandas, we should parametrize the existing tests to run them once on pandas dataframes and once on polars dataframes?

jeromedockes commented 8 months ago

as is done in this test for the agg joiner for example

GaelVaroquaux commented 8 months ago

I wonder if instead of creating separate tests to compare polars to pandas, we should parametrize the existing tests to run them once on pandas dataframes and once on polars dataframes?

Fine with me. Whatever makes the code more natural and readable.