Skip to content

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

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
jreback opened this issue May 1, 2016 · 7 comments
Closed

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

jreback opened this issue May 1, 2016 · 7 comments
Labels
Compat pandas objects compatability with Numpy or Python functions Sparse Sparse Data Type
Milestone

Comments

@jreback
Copy link
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 jreback added Sparse Sparse Data Type Compat pandas objects compatability with Numpy or Python functions labels May 1, 2016
@jreback jreback added this to the 0.18.1 milestone May 1, 2016
@jreback jreback changed the title API: sparse.cumsum should default to stats axis ( API: sparse.cumsum should default to stats axis May 1, 2016
@jreback
Copy link
Contributor Author

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

@jreback
Copy link
Contributor Author

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

@gfyoung
Copy link
Member

gfyoung commented May 1, 2016

@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.

@jreback
Copy link
Contributor Author

jreback commented May 1, 2016

see the dense impl

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

@gfyoung
Copy link
Member

gfyoung commented May 1, 2016

Ah, I see. Just a simple:

if axis is None:
   axis = self._stat_axis_number

before making the self.apply function call

@jreback
Copy link
Contributor Author

jreback commented May 1, 2016

yep but merging soon
do after and need tests

@gfyoung
Copy link
Member

gfyoung commented May 1, 2016

Yes, indeed, certainly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Sparse Sparse Data Type
Projects
None yet
Development

No branches or pull requests

2 participants