Skip to content

Exposing conversion to Float32 in the Cleaner - #1440

Merged
GaelVaroquaux merged 6 commits into
skrub-data:mainfrom
rcap107:enh-cleaner-float32
Jun 16, 2025
Merged

GaelVaroquaux merged 6 commits into
skrub-data:mainfrom
rcap107:enh-cleaner-float32

Conversation

@rcap107

@rcap107 rcap107 commented Jun 13, 2025

Copy link
Copy Markdown
Member

Fixes #1439

@rcap107
rcap107 marked this pull request as ready for review June 13, 2025 08:30
@rcap107

rcap107 commented Jun 13, 2025

Copy link
Copy Markdown
Member Author

I'm wondering if converting to float32 should be an option for the config manager #1427

Comment thread skrub/_table_vectorizer.py Outdated
datetime_format : str, default=None
The format to use when parsing dates. If None, the format is inferred.

convert_float32 : bool, default=False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are using a different API as in the TableVectorizer (and as in a few other objects in scikit-learn that do type conversions, I believe).

I understand why, but the differences are quite large (different parameter name, different type of accepted value), and it will make it hard for the user to memorize. Can we get closer to the canonical API?

@GaelVaroquaux GaelVaroquaux Jun 13, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eg we could have numerical_dtype="float32"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the option is either "convert to float32", or "keep as is", if we use numerical_dtype="float32", what would be the other option?

I am open to changing the name of the parameter, but given that in this case it's really an on-off switch I think a boolean flag makes the most sense

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have an example of the scikit-learn objects?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For OneHotEncoder and others, we usually have a dtype parameter (https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html) to control the output dtype.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like numerical_dtype=None by default when numbers are not converted and numerical_dtype="float32" when the conversion must be done?

tbh I'm still not convinced this is better than having boolean flag here

@GaelVaroquaux

GaelVaroquaux commented Jun 13, 2025 via email

Copy link
Copy Markdown
Member

@GaelVaroquaux

GaelVaroquaux commented Jun 13, 2025 via email

Copy link
Copy Markdown
Member

@rcap107

rcap107 commented Jun 13, 2025

Copy link
Copy Markdown
Member Author

ready for review

Comment thread skrub/tests/test_table_vectorizer.py Outdated

vectorizer = Cleaner(numerical_dtype="float32")
out = vectorizer.fit_transform(X)
assert sbd.is_float(out["float"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this check for float, or float32?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, it only checks for float

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I just realized that this test, like all other tests in table_vectorizer, is not testing for pandas, pandas-nullable-types and polars

I'll do a quick fix to get this test through, but we'll have to update all tests

@GaelVaroquaux

GaelVaroquaux commented Jun 13, 2025 via email

Copy link
Copy Markdown
Member

@jeromedockes

jeromedockes commented Jun 15, 2025

Copy link
Copy Markdown
Member

just a small comment, I think in skrub we have been using "numeric" and not "numericAL" everywhere so it would be nice to stay consistent

@GaelVaroquaux GaelVaroquaux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@GaelVaroquaux
GaelVaroquaux merged commit b3ab8f6 into skrub-data:main Jun 16, 2025
@rcap107
rcap107 deleted the enh-cleaner-float32 branch September 4, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose the conversion to float32 as a parameter for the Cleaner

4 participants