Skip to content

Backport 4619, BUG: many functions silently drop keepdims kwarg #7736

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 1 commit into from
Jun 13, 2016

Conversation

charris
Copy link
Member

@charris charris commented Jun 12, 2016

change test from type(a) is not mu.ndarray to
not isinstance(a, mu.ndarray)

Because every sub-class of ndarray is not guaranteed to implement
keepdims as a kwarg, when wrapping these methods care must be taken.

The previous behavior was to silently eat the kwarg when dealing with
a sub-class of ndarray.

Now, if keepdims=np._NoValue (the new default) it is not passed
through to the underlying function call (so the default value of
keepdims is now controlled by the sub-class). If keepdims is not
np._NoValue then it is passed through and will raise an exception if
the sub-class does not support the kwarg.

A special case in nanvar was required to deal with matrix that previously
relied on fromnumeric silently dropping keepdims.

@charris charris added component: numpy.ma masked arrays 08 - Backport Used to tag backport PRs labels Jun 12, 2016
@charris charris added this to the 1.11.1 release milestone Jun 12, 2016
@charris
Copy link
Member Author

charris commented Jun 12, 2016

Not sure this enhancement/bugfix should be backported, but I am kind of thinking of 1.11.x as a long term release because it fits with many downstream release schedules, supports Python 2.6, and has been relatively trouble free.

@@ -883,17 +919,29 @@ def nanpercentile(a, q, axis=None, out=None, overwrite_input=False,
* nearest: ``i`` or ``j``, whichever is nearest.
* midpoint: ``(i + j) / 2``.
keepdims : bool, optional
<<<<<<< 35b5f5be1ffffada84c8be207e7b8b196a58f786
Copy link
Member

Choose a reason for hiding this comment

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

Unresolved merge conflict.

@seberg
Copy link
Member

seberg commented Jun 12, 2016

I think I am OK with backporting this, there was another PR which added this and some more to the masked values, which would probably be more dubious. Should have another look at it maybe though.

change test from `type(a) is not mu.ndarray` to
`not isinstance(a, mu.ndarray)`

Because every sub-class of ndarray is not guaranteed to implement
`keepdims` as a kwarg, when wrapping these methods care must be taken.

The previous behavior was to silently eat the kwarg when dealing with
a sub-class of ndarray.

Now, if `keepdims=np._NoValue` (the new default) it is not passed
through to the underlying function call (so the default value of
`keepdims` is now controlled by the sub-class).  If `keepdims` is not
`np._NoValue` then it is passed through and will raise an exception if
the sub-class does not support the kwarg.

A special case in nanvar was required to deal with `matrix` that previously
relied on `fromnumeric` silently dropping `keepdims`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 08 - Backport Used to tag backport PRs component: numpy.ma masked arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants