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: SparseDataFrame indexing sometimes loses fill_value of empty columns in 0.24 #25378

Closed
scottgigante opened this issue Feb 19, 2019 · 4 comments · Fixed by #28425
Closed
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Sparse Sparse Data Type

Comments

@scottgigante
Copy link
Contributor

scottgigante commented Feb 19, 2019

Code Sample, a copy-pastable example if possible

import numpy as np
import pandas as pd
X = pd.SparseDataFrame([[0,1], [0,0]], default_fill_value=0.0)
## Good behaviour
X.loc[0].to_numpy()
# array([0., 1.])
X.loc[[0]].to_numpy()
# array([[0., 1.]])
X.iloc[0].to_numpy()
# array([0., 1.])
## Bad behaviour
X.iloc[[0]].to_numpy()
# array([[nan, 1]], dtype=object)
X.loc[[True, False]].to_numpy()
# array([[nan, 1]], dtype=object)

Problem description

Indexing a SparseDataFrame with iloc and more than a single row number should return the same result as indexing the same rows with loc and the corresponding indices. Instead, iloc drops column fill_value for any column with no non-zero entries.

Expected Output

All commands should return array([0., 1.]) (allowing for differences between 1- and 2-D output.) The last two (iloc with fancy indexing, and loc with boolean indexing) returns instead array([nan, 1.]).

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-17763-Microsoft
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.1
pytest: None
pip: 18.0
setuptools: 40.2.0
Cython: 0.29
numpy: 1.15.1
scipy: 1.2.0
pyarrow: None
xarray: None
IPython: 7.1.1
sphinx: 1.6.7
patsy: None
dateutil: 2.7.3
pytz: 2018.3
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 2.2.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Feb 20, 2019 via email

@scottgigante
Copy link
Contributor Author

I don't see any mention of this in the documentation. Can you please post a link?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Feb 20, 2019 via email

@gfyoung gfyoung added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Sparse Sparse Data Type Bug labels Feb 21, 2019
@gfyoung
Copy link
Member

gfyoung commented Feb 21, 2019

Marking as a bug for now, but given that this isn't a regression, it would likely be patched in 0.25.0. However, even with the deprecation, a patch would be welcomed if it isn't too difficult.

@gfyoung gfyoung added this to the Contributions Welcome milestone Feb 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants