Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import scipy
import pandas as pd
coo = scipy.sparse.coo_matrix([[False,True],[True,False]])
pd.DataFrame.sparse.from_spmatrix(coo) # results in FutureWarning
coo = scipy.sparse.coo_matrix([[0,1],[1,0]])
pd.DataFrame.sparse.from_spmatrix(coo) # no warnings
Issue Description
Attempting to use from_spmatrix() with a boolean-type scipy.sparse matrix raises a warning about arbitrary scalar fill_value:
FutureWarning: Allowing arbitrary scalar fill_value in SparseDtype is deprecated. In a future version, the fill_value must be a valid value for the SparseDtype.subtype.
pd.DataFrame.sparse.from_spmatrix(coo)
but using sparse integer dtype for the scipy matrix does not. I don't understand why this occurs, but it seems like from_spmatrix should be able to handle both of these scenarios. Also, there is no argument to from_spmatrix to specify a type, so it is unclear what the user should do about this future warning if anything.
Thanks for the report, the result appears correct on main where the warning has been removed. This warning should not be surfaced to the user. Further investigations and PRs to fix are welcome!
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Attempting to use from_spmatrix() with a boolean-type scipy.sparse matrix raises a warning about arbitrary scalar fill_value:
but using sparse integer dtype for the scipy matrix does not. I don't understand why this occurs, but it seems like from_spmatrix should be able to handle both of these scenarios. Also, there is no argument to from_spmatrix to specify a type, so it is unclear what the user should do about this future warning if anything.
Expected Behavior
No warning, uses dtype matching input
Installed Versions