Skip to content

feat: add accept_numeric kwarg to ToCategorical - #2252

Draft
lisaleemcb wants to merge 4 commits into
skrub-data:mainfrom
lisaleemcb:issue2219_behaviour_toCat
Draft

feat: add accept_numeric kwarg to ToCategorical#2252
lisaleemcb wants to merge 4 commits into
skrub-data:mainfrom
lisaleemcb:issue2219_behaviour_toCat

Conversation

@lisaleemcb

Copy link
Copy Markdown
Contributor

The encoder ToCategorical now also accepts type int columns, in addition to str and categorical dtypes via setting the new kwarg accept_numeric to 'int'. In addition, float columns will be accepted if accept_numeric='all'.

As currently implemented, the new default is accept_numeric='int' which means that columns of strings, categoricals, and ints will be marked as categorical after performing fit_transform. Note this is different from the current default behaviour, which only accepts strings, and categoricals, and will raise an error otherwise. The current default can be recovered by setting accept_numeric=None.

The rationale for the new default is that integers are used in many datasets to represent categories. But this would make it a breaking change for direct users, so perhaps we should discuss.

However, note that this change in the default would not affect the behaviour of the TableVectorizer, as the numerical columns are currently not selected to be sent to the ToCategorical encoder. Thanks to @rcap107 for beaucoup help with understanding its behaviour.

PS Also changed the docstring to make it more concise.

@rcap107 rcap107 added this to the Release 0.10.1 milestone Aug 25, 2026

@rcap107 rcap107 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.

Thanks for the PR @lisaleemcb! There are still a few things that we need to clarify, but here is an early review with some comments

Comment thread skrub/_to_categorical.py Outdated
Comment thread skrub/_to_categorical.py Outdated
Comment thread skrub/tests/test_to_categorical.py
Comment thread skrub/tests/test_to_categorical.py Outdated
@lisaleemcb

Copy link
Copy Markdown
Contributor Author

Note this PR is still failing because of the test case where the integer column contains None/null values. This desired behaviour in this situation is still tbd, and should be discussed.

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.

Change the behavior of ToCategorical so that it no longer rejects numeric features

2 participants