Wrong result of pandas.sparse.series.SparseSeries.loc with indexer of length 1 #15447

Closed
toobaz opened this Issue Feb 17, 2017 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

toobaz commented Feb 17, 2017

Code Sample, a copy-pastable example if possible

In [3]: idx = pd.MultiIndex.from_tuples([('A', 0), ('A', 1), ('B', 0), ('C', 0), ('C', 1)])

In [4]: orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=idx)

In [5]: sparse = orig.to_sparse()

In [6]: sparse.loc[['A']]
Out[6]: 
A   NaN
dtype: float64
BlockIndex
Block locations: array([], dtype=int32)
Block lengths: array([], dtype=int32)

Problem description

It should return as below

Expected Output

In [7]: orig.loc[['A']].to_sparse()
Out[7]: 
A  0    1.0
   1    NaN
dtype: float64
BlockIndex
Block locations: array([0], dtype=int32)
Block lengths: array([1], dtype=int32)

Output of pd.show_versions()

INSTALLED VERSIONS

commit: f65a641
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.7.0-1-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: it_IT.utf8
LOCALE: it_IT.UTF-8

pandas: 0.19.0+473.gf65a641
pytest: 3.0.6
pip: 8.1.2
setuptools: 28.0.0
Cython: 0.23.4
numpy: 1.12.0
scipy: 0.18.1
xarray: None
IPython: 5.1.0.dev
sphinx: 1.4.8
patsy: 0.3.0-dev
dateutil: 2.5.3
pytz: 2015.7
blosc: None
bottleneck: 1.2.0
tables: 3.2.2
numexpr: 2.6.0
feather: None
matplotlib: 2.0.0rc2
openpyxl: 2.3.0
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: 0.999
httplib2: 0.9.1
apiclient: 1.5.2
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_datareader: 0.2.1

toobaz changed the title from Wrong result of ``.loc`` on ``pandas.sparse.series.SparseSeries`` with indexer of length 1 to Wrong result of pandas.sparse.series.SparseSeries.loc with indexer of length 1 Feb 17, 2017

@toobaz toobaz added a commit to toobaz/pandas that referenced this issue Feb 17, 2017

@toobaz toobaz BUG: Trivial fix to #15447 9a38213

toobaz referenced this issue Feb 17, 2017

Closed

BUG: Trivial fix to #15447 #15448

2 of 4 tasks complete

jreback added this to the Next Major Release milestone Feb 18, 2017

kawochen referenced this issue Feb 18, 2017

Open

BUG: Sparse master issue #10627

11 of 18 tasks complete

@toobaz toobaz added a commit to toobaz/pandas that referenced this issue Feb 20, 2017

@toobaz toobaz BUG: Drop faulty and redundant reindex() for SparseSeries
closes #15447
56d905f
Contributor

toobaz commented Feb 20, 2017

The bug actually comes from SparseSeries.reindex()

In [8]: sparse.reindex(['A'], level=0)
Out[8]: 
A   NaN
dtype: float64
BlockIndex
Block locations: array([], dtype=int32)
Block lengths: array([], dtype=int32)

PR on its way.

@jreback jreback modified the milestone: 0.20.0, Next Major Release Feb 24, 2017

@toobaz toobaz added a commit to toobaz/pandas that referenced this issue Mar 3, 2017

@toobaz toobaz BUG: Drop faulty and redundant reindex() for SparseSeries
closes #15447
55b99f8

jreback closed this in c52ff68 Mar 7, 2017

@AnkurDedania AnkurDedania added a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017

@toobaz @AnkurDedania toobaz + AnkurDedania BUG: fix SparseSeries reindex by using Series implementation
closes #15447

Author: Pietro Battiston <me@pietrobattiston.it>

Closes #15461 from toobaz/drop_sparse_reindex and squashes the following commits:

9084246 [Pietro Battiston] Test SparseSeries.reindex with fill_value and nearest
d6a46da [Pietro Battiston] Use _shared_docs for documentation
922c7b0 [Pietro Battiston] Test "copy" argument
af99190 [Pietro Battiston] Whatsnew
7945cb4 [Pietro Battiston] Tests for .loc() and .reindex() on sparse series with MultiIndex
55b99f8 [Pietro Battiston] BUG: Drop faulty and redundant reindex() for SparseSeries
9ee6980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment