Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: pd.Arrays.SparseArray warning inconsistencies when contained in a pd.DataFrame (potential false positive) #58582

Open
3 tasks done
mflova opened this issue May 5, 2024 · 0 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@mflova
Copy link

mflova commented May 5, 2024

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

import numpy as np
import pandas as pd

df = pd.DataFrame()
df[0] = [2]
df[1] = pd.arrays.SparseArray([2], fill_value=np.nan, dtype=np.float64)
df.count()  # FutureWarning: Allowing arbitrary scalar fill_value in SparseDtype is deprecated
df[0].count()  # OK
df[1].count()  # OK

series = pd.Series(pd.arrays.SparseArray([2], fill_value=2, dtype=np.float64))
series.count()  # OK

Issue Description

FutureWarning is raised when any object of type pd.Arrays.SparseArray is contained in a pd.DataFrame type object. I seem to be explicit about the input parameters of the sparse array and yet I am getting the warning. Something interesting is that this warning is not being displayed when the object itself is not contained within the dataframe, which makes me wonder if this warning is "real" warning or just a false positive. If my SparseArray is not well defined, then I would expectd that invoking count on the pd.Series object that contains the pd.SparseArray would also trigger a warning.

This warning is being displayed by other methods that involve count (i,e info())

EDIT: It seems this warning is being triggered because when calling count on the whole Dataframe and this one contains at least one SparseArray and one "normal" columns, all the types are coherced into a pd.Series[int64], which ends up triggering the warning. Therefore, how this can be fixed?

Expected Behavior

No warning is raised

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.10.11.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 151 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United Kingdom.1252

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 69.5.1
pip : 23.3.1
Cython : None
pytest : 7.4.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.4
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@mflova mflova added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant