Skip to content

[test][python] fix pandas DeprecationWarning about is_sparse function - #6532

Merged
jameslamb merged 2 commits into
masterfrom
pandas-sparse
Jul 10, 2024
Merged

jameslamb merged 2 commits into
masterfrom
pandas-sparse

Conversation

@StrikerRUS

Copy link
Copy Markdown
Collaborator

Fix the following error:

DeprecationWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.

LightGBM requires pandas>=0.24.0
https://github.com/microsoft/LightGBM/blob/6c76b6b72ad77ba85285053b8aae209f3a5060ad/python-package/pyproject.toml#L44-L46
So I checked that pd.SparseDtype is available in that version:
https://pandas.pydata.org/pandas-docs/version/0.24/reference/api/pandas.SparseDtype.html

Also, they've been performing isinstance check under the hood since the begging:
https://github.com/pandas-dev/pandas/blob/83eb2428ceb6257042173582f3f436c2c887aa69/pandas/core/dtypes/common.py#L216-L219

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

Awesome, thanks!

And thank you for the research. We do now also have CI jobs testing against the oldest versions of Python dependencies:

https://github.com/microsoft/LightGBM/blob/4292b1683777a109f4ebc30a9b1c891bf4689b8e/.github/workflows/python_package.yml#L120

and the latest (even pre-released) versions:

https://github.com/microsoft/LightGBM/blob/4292b1683777a109f4ebc30a9b1c891bf4689b8e/.github/workflows/python_package.yml#L93

@jameslamb
jameslamb merged commit cd4459a into master Jul 10, 2024
@jameslamb
jameslamb deleted the pandas-sparse branch July 10, 2024 16:20
@StrikerRUS

Copy link
Copy Markdown
Collaborator Author

We do now also have CI jobs testing against the oldest versions of Python dependencies

Thank you for letting me know! That's great!

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants