BUG: pd.Arrays.SparseArray
warning inconsistencies when contained in a pd.DataFrame
(potential false positive)
#58582
Labels
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
Issue Description
FutureWarning
is raised when any object of typepd.Arrays.SparseArray
is contained in apd.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 mySparseArray
is not well defined, then I would expectd that invokingcount
on thepd.Series
object that contains thepd.SparseArray
would also trigger a warning.This warning is being displayed by other methods that involve
count
(i,einfo()
)EDIT: It seems this warning is being triggered because when calling
count
on the whole Dataframe and this one contains at least oneSparseArray
and one "normal" columns, all the types are coherced into apd.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
The text was updated successfully, but these errors were encountered: