Skip to content

BUG: Sparse[bool] type allows any fill_value #45004

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

Closed
3 tasks done
bdrum opened this issue Dec 21, 2021 · 3 comments
Closed
3 tasks done

BUG: Sparse[bool] type allows any fill_value #45004

bdrum opened this issue Dec 21, 2021 · 3 comments
Labels
API Design Bug Needs Triage Issue that has not been reviewed by a pandas team member Sparse Sparse Data Type

Comments

@bdrum
Copy link
Contributor

bdrum commented Dec 21, 2021

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 master branch of pandas.

Reproducible Example

a = pd.arrays.SparseArray([1, 0, 0, 1], dtype=pd.SparseDtype(np.bool8, 12))
a
#[True, False, False, True]
#Fill: 12
#IntIndex
#Indices: array([0, 1, 2, 3])

Issue Description

According to discussion in #44955 I think that Sparse[bool] type should have only three available value: True, False or nan.

Actually I've already tried to implement deprecation of setting any value instead of mentioned list, but plenty of test was failed. So I've decided to get approval from community.

What do you think?

BTW we can just use implicit conversion of any fill_value to bool type

Expected Behavior

a = pd.arrays.SparseArray([1, 0, 0, 1], dtype=pd.SparseDtype(np.bool8, 12))
ValueError
fill_value must be True, False or nan for boolean type. Got 12 instead

Installed Versions

INSTALLED VERSIONS ------------------ commit : 2cc9ab3 python : 3.8.12.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19044 machine : AMD64 processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : Russian_Russia.1252

pandas : 1.4.0.dev0+1436.g2cc9ab3ef7
numpy : 1.21.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3
setuptools : 58.0.4
Cython : 0.29.24
pytest : 6.2.5
hypothesis : 6.23.3
sphinx : 4.2.0
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.28.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fsspec : 2021.10.1
fastparquet : None
gcsfs : 2021.10.1
matplotlib : 3.4.3
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : 2021.10.1
scipy : 1.7.1
sqlalchemy : 1.4.25
tables : 3.6.1
tabulate : 0.8.9
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.53.1

@bdrum bdrum added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 21, 2021
@jbrockmendel jbrockmendel added Sparse Sparse Data Type API Design labels Dec 23, 2021
@jbrockmendel
Copy link
Member

xref #23124

@bdrum
Copy link
Contributor Author

bdrum commented Dec 23, 2021

Ah, I think this issue is a dup. Sorry, actually tried to check on it before creation.

@mroeschke
Copy link
Member

Closing as a dupe of #23124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Bug Needs Triage Issue that has not been reviewed by a pandas team member Sparse Sparse Data Type
Projects
None yet
Development

No branches or pull requests

3 participants