Skip to content

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

Merged
merged 24 commits into from
Apr 28, 2021
Merged

Min max sparse #41159

merged 24 commits into from
Apr 28, 2021

Conversation

taytzehao
Copy link
Contributor

@pep8speaks
Copy link

pep8speaks commented Apr 26, 2021

Hello @taytzehao! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-04-27 08:13:18 UTC

@@ -874,7 +874,7 @@ Sparse

- Bug in :meth:`DataFrame.sparse.to_coo` raising ``KeyError`` with columns that are a numeric :class:`Index` without a 0 (:issue:`18414`)
- Bug in :meth:`SparseArray.astype` with ``copy=False`` producing incorrect results when going from integer dtype to floating dtype (:issue:`34456`)
-
- Bug in :meth:`max` and `min` for SparseArrat type do not exist (:issue:`40921`)
Copy link
Contributor

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`



def test_maxmin():
data = np.arange(10).astype(float)
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also a tests on all-NaN

@jreback jreback added Sparse Sparse Data Type Reduction Operations sum, mean, min, max, etc. labels Apr 26, 2021
@jreback
Copy link
Contributor

jreback commented Apr 26, 2021

pre-commit is failing, pls run the hooks: https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#pre-commit

@jreback jreback added this to the 1.3 milestone Apr 27, 2021
@jreback
Copy link
Contributor

jreback commented Apr 27, 2021

cc @jbrockmendel

@@ -877,7 +877,7 @@ Sparse

- Bug in :meth:`DataFrame.sparse.to_coo` raising ``KeyError`` with columns that are a numeric :class:`Index` without a 0 (:issue:`18414`)
- Bug in :meth:`SparseArray.astype` with ``copy=False`` producing incorrect results when going from integer dtype to floating dtype (:issue:`34456`)
-
- Bug in :class:`SparseArray` type as :meth:`max` and :meth:`min` do not exist (:issue:`40921`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "Implemented :meth:`SparseArray.min` and :meth:`SparseArray.max` (:issue:`40921`)"

if self.sp_index.ngaps > 0 and np.all(self._valid_sp_values < 0):

if self.size > 0 and self._valid_sp_values.size == 0:
return np.nan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldnt self.fill_value be relevant here?


return 0
else:
return np.amax(self._valid_sp_values, axis)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for np.amax instead of np.max?

@jreback jreback merged commit d3c6ab4 into pandas-dev:master Apr 28, 2021
@jreback
Copy link
Contributor

jreback commented Apr 28, 2021

thanks @taytzehao

@jbrockmendel
Copy link
Member

@jreback this wasnt ready, in particular #41159 (comment) looks sketchy

@jreback
Copy link
Contributor

jreback commented Apr 28, 2021

ok feel free to revert

@jbrockmendel
Copy link
Member

@taytzehao would you prefer to revert or to address this in a follow-up?

yeshsurya pushed a commit to yeshsurya/pandas that referenced this pull request May 6, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reduction Operations sum, mean, min, max, etc. Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: max()/min() don't work on DataFrames constructed from scipy sparse matrix
4 participants