FIX Fix OpenML dataset parsing with pandas>=3.1.0.dev0 - #34902
Conversation
| @@ -432,6 +432,9 @@ def _pandas_arff_parser( | |||
| single_quote_pattern = re.compile(r"^'(?P<contents>.*)'$") | |||
|
|
|||
| def strip_single_quotes(input_string): | |||
There was a problem hiding this comment.
On line 438 we try to do a regex to an int (with the nightly build version of pandas).
With the environment I created locally using the nightly build, one can see the following at this point in the code when running the new test on test_arff_parser.py:test_pandas_arff_parser_numeric_nominal_categories:
(Pdb) input_string
1
(Pdb) match = re.search(single_quote_pattern, input_string)
*** TypeError: expected string or bytes-like object, got 'int'
Note: this error happens when we comment out lines 435 and 436 and run the test.
scipy-dev build due to the change in pandas' nightly version
scipy-dev build due to the change in pandas' nightly versionscipy-dev build due to the change in pandas'
scipy-dev build due to the change in pandas' scipy-dev build due to the change in pandas
|
Thanks for the PR! I think adding a changelog makes sense. Also if this is not too much work it would be nice to find the pandas PR that changed the behaviour, in principle this is a recent PR, since it started failing a few days ago in #34892 and pandas development wheels are updated often (daily by a quick look at https://anaconda.org/channels/scientific-python-nightly-wheels/packages/pandas/files?sort=-updated_at) |
scipy-dev build due to the change in pandas|
I think that the pandas PR that changed the behaviour is this one: pandas-dev/pandas#64659 |
|
With the pandas' PR I realised that leading zeros are gone. I need to investigate more but it seems that if a category that OpenML calls "01", it will become 1: Edit: I'm searching if this change affects other places in scikit-learn |
cakedev0
left a comment
There was a problem hiding this comment.
LGTM, simple fix, good test 👍
|
Thanks! |
Reference Issues/PRs
Closes #34894
Fixes #34892
What does this implement/fix? Explain your changes.
The bug that was found by the CI failure is in sklearn/datasets/_arff_parser.py line 435-447:
_pandas_arff_parserstrips single quotes on categories as a post-processing steps if needed.This part of the code (on the main branch) assumes that every categorical value is a
str.But
pd.read_csv(..., dtype="category")on unquoted numeric values yieldsobjectwith pandas 2.3.3.And it yields
int64with pandas 3.1.0.dev0.The pandas' PR that seems to have changed the behaviour: pandas-dev/pandas#64659
One can verify that with:
Where
sklearn-scipy-devwas my local environment with the nightly builds.The output of the block above is:
The test that I added fails without this check on
_pandas_arff_parser:if not isinstance(input_string, str)For this PR I run this command and committed the generated files:
AI usage disclosure
I used AI assistance for:
Any other comments?
Not ready to review - I want to see if there are other failures