API: sparse.cumsum should default to stats axis #13048

Closed
jreback opened this Issue May 1, 2016 · 7 comments

Comments

Projects
None yet
2 participants
Contributor

jreback commented May 1, 2016

xref #12810

In [1]: sp = pd.SparseDataFrame([1, 2, 3])

In [2]: np.cumsum(sp)
ValueError: No axis named None for object type <class 'pandas.sparse.frame.SparseDataFrame'>

In [3]: np.cumsum(sp, axis=0)
Out[3]: 
     0
0  1.0
1  3.0
2  6.0

In [4]: np.cumsum(sp, axis=1)
Out[4]: 
     0
0  1.0
1  2.0
2  3.0

jreback added this to the 0.18.1 milestone May 1, 2016

jreback changed the title from API: sparse.cumsum should default to stats axis ( to API: sparse.cumsum should default to stats axis May 1, 2016

Contributor

jreback commented May 1, 2016

cc @gfyoung merging #12810

but I think this should default. Need to systematically check all of the cum functions.
(axis = 0). dense already does this. (yes the axis is passed as None but its set if its None.

cc @sinhrks

Contributor

jreback commented May 1, 2016

e.g. [6] works

In [4]: np.cumsum(sp, axis=0)
Out[4]: 
     0
0  1.0
1  3.0
2  6.0

In [5]: np.cumsum(sp.to_dense(), axis=0)
Out[5]: 
     0
0  1.0
1  3.0
2  6.0

In [6]: np.cumsum(sp.to_dense())
Out[6]: 
     0
0  1.0
1  3.0
2  6.0
Member

gfyoung commented May 1, 2016 edited

@jreback : I'm not sure I fully understand. How do you want to handle the case when axis=None (when you say "stats" axis)? In numpy it's easy because you just flatten the array, but that doesn't make any sense with a DataFrame.

Contributor

jreback commented May 1, 2016

see the dense impl

it needs to be 0 (which is the stats axis)

Member

gfyoung commented May 1, 2016 edited

Ah, I see. Just a simple:

if axis is None:
   axis = self._stat_axis_number

before making the self.apply function call

Contributor

jreback commented May 1, 2016

yep but merging soon
do after and need tests

Member

gfyoung commented May 1, 2016

Yes, indeed, certainly!

@jreback jreback modified the milestone: 0.18.2, 0.18.1 May 2, 2016

@gfyoung gfyoung added a commit to gfyoung/pandas that referenced this issue May 6, 2016

@gfyoung gfyoung BUG: Default to stat axis for SparseDataFrame when axis=None
Closes gh-13048
da30e21

jreback closed this in c089110 May 7, 2016

@nps nps added a commit to nps/pandas that referenced this issue May 17, 2016

@gfyoung @nps gfyoung + nps BUG: Default to stat axis for SparseDataFrame when axis=None
Title is self-explanatory.  Closes #13048.

Author: gfyoung <gfyoung17@gmail.com>

Closes #13066 from gfyoung/stats-axis-default and squashes the following commits:

da30e21 [gfyoung] BUG: Default to stat axis for SparseDataFrame when axis=None
06e5693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment