-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Default to stat axis for SparseDataFrame when axis=None #13066
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
import operator | ||
|
||
import nose # noqa | ||
from numpy import nan | ||
import numpy as np | ||
import pandas as pd | ||
|
@@ -768,12 +767,19 @@ def _check(frame, orig): | |
self._check_all(_check) | ||
|
||
def test_count(self): | ||
result = self.frame.count() | ||
dense_result = self.frame.to_dense().count() | ||
|
||
result = self.frame.count() | ||
tm.assert_series_equal(result, dense_result) | ||
|
||
result = self.frame.count(axis=None) | ||
tm.assert_series_equal(result, dense_result) | ||
|
||
result = self.frame.count(axis=0) | ||
tm.assert_series_equal(result, dense_result) | ||
|
||
result = self.frame.count(1) | ||
dense_result = self.frame.to_dense().count(1) | ||
result = self.frame.count(axis=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this a problem with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. of course, so that's why need to test all of these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. Done. |
||
dense_result = self.frame.to_dense().count(axis=1) | ||
|
||
# win32 don't check dtype | ||
tm.assert_series_equal(result, dense_result, check_dtype=False) | ||
|
@@ -862,12 +868,19 @@ def setUp(self): | |
self.frame = SparseDataFrame(self.data, index=self.dates) | ||
|
||
def test_cumsum(self): | ||
result = self.frame.cumsum() | ||
expected = SparseDataFrame(self.frame.to_dense().cumsum()) | ||
|
||
result = self.frame.cumsum() | ||
tm.assert_sp_frame_equal(result, expected) | ||
|
||
result = self.frame.cumsum(axis=None) | ||
tm.assert_sp_frame_equal(result, expected) | ||
|
||
result = self.frame.cumsum(axis=0) | ||
tm.assert_sp_frame_equal(result, expected) | ||
|
||
def test_numpy_cumsum(self): | ||
result = np.cumsum(self.frame, axis=0) | ||
result = np.cumsum(self.frame) | ||
expected = SparseDataFrame(self.frame.to_dense().cumsum()) | ||
tm.assert_sp_frame_equal(result, expected) | ||
|
||
|
@@ -879,7 +892,16 @@ def test_numpy_cumsum(self): | |
tm.assertRaisesRegexp(ValueError, msg, np.cumsum, | ||
self.frame, out=result) | ||
|
||
def test_numpy_func_call(self): | ||
# no exception should be raised even though | ||
# numpy passes in 'axis=None' or `axis=-1' | ||
funcs = ['sum', 'cumsum', 'var', | ||
'mean', 'prod', 'cumprod', | ||
'std', 'min', 'max'] | ||
for func in funcs: | ||
getattr(np, func)(self.frame) | ||
|
||
if __name__ == '__main__': | ||
import nose # noqa | ||
import nose | ||
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], | ||
exit=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also (maybe in another function), run thru all stat methods (you can just assert that they don't raise), e.g. just do a loop for all named (stat functions).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where can I find all the statistics methods? I just CTRL+F for
axis=0
, and these were the only two, but I'm not sure how I would automate that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean? all of the methods in
DataFrame
are avaialbleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, but nevertheless, how do I automate going through all of the stat functions in
SparseDataFrame
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just out a list
mean count var etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not optimal, but I guess that should suffice.