Skip to content

BUG: masked mean unnecessarily overflowing #48378

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 10 commits into from
Sep 7, 2022

Conversation

phofl
Copy link
Member

@phofl phofl commented Sep 3, 2022

  • closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

Do we want to add mean to the Masked Array interface (I would say yes, but want to check anyway)? This would simplify things a bit.

cc @jorisvandenbossche

@phofl phofl added NA - MaskedArrays Related to pd.NA and nullable extension arrays Reduction Operations sum, mean, min, max, etc. labels Sep 3, 2022
@jorisvandenbossche
Copy link
Member

Ah, nice, this is possible now because we require numpy >= 1.20 (the where keyword was only added later to mean)

Do we want to add mean to the Masked Array interface (I would say yes, but want to check anyway)? This would simplify things a bit.

Yeah, I am not really sure why historically sum, prod, etc are methods, while mean is only handled inside _reduce

@phofl
Copy link
Member Author

phofl commented Sep 6, 2022

Yes, numpy now supports this in every version we need.

Ok great, confused me a little bit too

@phofl
Copy link
Member Author

phofl commented Sep 6, 2022

Added as method

@@ -191,7 +192,11 @@ def test_reductions_2d_axis0(self, data, method):
kwargs["ddof"] = 0

try:
result = getattr(arr2d, method)(axis=0, **kwargs)
if method == "mean":
Copy link
Member Author

@phofl phofl Sep 6, 2022

Choose a reason for hiding this comment

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

We have 2 all NA rows in our array that causes numpy to raise a RuntimeWarning with axis=0. Mean raised previously, so dtype was not checked below

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Looks good!

@phofl phofl merged commit b8ae9bb into pandas-dev:main Sep 7, 2022
@phofl phofl deleted the bug_masked_mean_overflows branch September 7, 2022 17:39
@phofl phofl added this to the 1.6 milestone Sep 7, 2022
@mroeschke mroeschke modified the milestones: 1.6, 2.0 Oct 13, 2022
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NA - MaskedArrays Related to pd.NA and nullable extension arrays Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants