pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.49k stars 17.87k forks source link

BUG: Sparse structures don't fully support value assignment #21818

Open kernc opened 6 years ago

kernc commented 6 years ago

Code Sample, a copy-pastable example if possible

>>> ss = pd.SparseSeries([1, 2])
>>> ss.iloc[0] = 3

-----------------------------------------------------------------------
TypeError: SparseArray does not support item assignment via setitem

Problem description

SparseSeries and SparseDataFrame don't support value assignment through some indexers (but might from others, i.e. ss[0] = 4 works).

Expected Output

Assignment works in all cases.

Output of pd.show_versions()

pandas 0.24.dev 5cb5880d8f1647e303ba52487dc867db838fd6e0
jorisvandenbossche commented 5 years ago

The same is true for Series[sparse]:

In [44]: ss = pd.Series(pd.SparseArray([1, 2])) 
    ...: ss.iloc[0] = 3  
...
TypeError: SparseArray does not support item assignment via setitem