Skip to content

Pandas 0.24 sparse restructure breaking _maybe_pandas_data() #4648

@r-archer37

Description

@r-archer37

Background: https://pandas.pydata.org/pandas-docs/stable/whatsnew/v0.24.0.html#sparse-data-structure-refactor

Summary: As of 0.24 sparse datatypes in pandas dataframes are represented like Sparse[int64, 0], which xgboost does not recognize as numeric.

Detail: In core._maybe_pandas_data() there is a loop that checks whether each column's dtype.name is in a hardcoded set of dtypes (

PANDAS_DTYPE_MAPPER = {'int8': 'int', 'int16': 'int', 'int32': 'int', 'int64': 'int',
). Because Pandas changed Sparse dtypes to have a name that doesn't match these, the check now fails on any sparse column. What is looked for is now represented in that column's dtype.subtype.

Possible solutions:
1 - Look at the dtype.name or dtype.subtype depending on whether the name starts with "Sparse"
2 - Instead of enumerating the acceptable datatypes, check each column with pd.api.types.is_numeric_dtype() and .is_bool_dtype()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions