-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Min max sparse #41159
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
Min max sparse #41159
Changes from 17 commits
b1fb854
7af63a2
c4259aa
043ae70
48f21c6
29fddab
e489742
fd75ac5
e0f4253
7b39607
3b22ab2
02d7f32
c6fe7e2
dddb6f6
9c03b52
227c282
5dabba3
85a99b4
0e6a384
dc7b704
10c40e5
13545b4
ff83373
9e5fe39
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 |
---|---|---|
|
@@ -1392,6 +1392,24 @@ def mean(self, axis=0, *args, **kwargs): | |
nsparse = self.sp_index.ngaps | ||
return (sp_sum + self.fill_value * nsparse) / (ct + nsparse) | ||
|
||
|
||
def max(self, axis=0, *args, **kwargs): | ||
nv.validate_max(args, kwargs) | ||
|
||
if self.sp_index.ngaps > 0 and np.all(self._valid_sp_values < 0): | ||
return 0 | ||
else: | ||
return np.amax(self._valid_sp_values, axis) | ||
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. any particular reason for np.amax instead of np.max? |
||
|
||
|
||
def min(self, axis=0, *args, **kwargs): | ||
nv.validate_min(args, kwargs) | ||
|
||
if self.sp_index.ngaps > 0 and np.all(self._valid_sp_values > 0): | ||
return 0 | ||
else: | ||
return np.amin(self._valid_sp_values, axis) | ||
|
||
# ------------------------------------------------------------------------ | ||
# Ufuncs | ||
# ------------------------------------------------------------------------ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1311,3 +1311,17 @@ def test_dropna(fill_value): | |
df = pd.DataFrame({"a": [0, 1], "b": arr}) | ||
expected_df = pd.DataFrame({"a": [1], "b": exp}, index=pd.Int64Index([1])) | ||
tm.assert_equal(df.dropna(), expected_df) | ||
|
||
|
||
def test_maxmin(): | ||
data = np.arange(10).astype(float) | ||
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. can you make sure some NaNs are in this, and assert that we are correctly hitting those (can parameterize to do that) 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. also a tests on all-NaN |
||
max_out = SparseArray(data).max() | ||
min_out = SparseArray(data).min() | ||
assert max_out == 9 | ||
assert min_out == 0 | ||
|
||
data = data * (-1) | ||
max_out = SparseArray(data).max() | ||
min_out = SparseArray(data).min() | ||
assert max_out == 0 | ||
assert min_out == -9 |
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.
spelling here. also pls use the direct reference e.g.
:class:`SparseArray`