Skip to content

BUG: regression in master for DataFrame.sparse.from_spmatrix #59212

@bmreiniger

Description

@bmreiniger

Pandas version checks

  • I have checked that this issue has not already been reported.

  • 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

from scipy.sparse import eye from pandas import DataFrame DataFrame.sparse.from_spmatrix(eye(5))

Issue Description

(This bug does not exist on the latest version of pandas, but that checkbox was required to submit the issue.)

In main branch, the example produces a frame with entries 1.0 and NaN (sparse, with fill_value nan).

PR #59064 corrected a bug for other dtypes, but introduced this regression for float dtype.

Expected Behavior

In latest version (2.2.2) and earlier, produces a frame with entries 1.0 and 0.0 (sparse, with fill_value 0).

Installed Versions

INSTALLED VERSIONS

commit : 69fe98d
python : 3.12.4
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United States.1252

pandas : 3.0.0.dev0+1170.g69fe98dda
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
pip : 24.0
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : 3.9.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : 8.2.2
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BugNeeds DiscussionRequires discussion from core team before further actionSparseSparse Data Type

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions