Skip to content

BUG: MaskedArray.count treats negative axes incorrectly #7515

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
Apr 5, 2016

Conversation

ahaldane
Copy link
Member

@ahaldane ahaldane commented Apr 5, 2016

Follow up to #5706. Fixes #7509

if len(axes) != len(set(axes)):
raise ValueError("duplicate value in 'axis'")
if np.any([a < 0 or a >= self.ndim for a in axes]):
raise ValueError("'axis' entry is out of bounds")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe IndexError?

exception IndexError

Raised when a sequence subscript is out of range. (Slice indices are silently truncated to fall in the allowed range; if an index is not an integer, TypeError is raised.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm just copying ufunc behavior here:

>>> np.ones((2,3)).all(axis=8)
ValueError: 'axis' entry is out of bounds

@charris charris merged commit 537d35c into numpy:master Apr 5, 2016
@charris
Copy link
Member

charris commented Apr 5, 2016

OK, we'll go with it. Thanks Allan.

@cgohlke
Copy link
Contributor

cgohlke commented Jun 30, 2016

Can this be backported to numpy 1.11.x?
Scipy 0.18.0rc1 fails one test due to this:

Running unit tests for scipy
NumPy version 1.11.1
NumPy relaxed strides checking option: False
NumPy is installed in X:\Python35\lib\site-packages\numpy
SciPy version 0.18.0rc1
SciPy is installed in X:\Python35\lib\site-packages\scipy
Python version 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)]
nose version 1.3.7
<snip>
======================================================================
ERROR: test_mstats_basic.TestKruskal.test_result_attributes
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python35\lib\site-packages\nose\case.py", line 198, in runTest
    self.test(*self.arg)
  File "X:\Python35\lib\site-packages\scipy\stats\tests\test_mstats_basic.py", line 708, in test_result_attributes
    res = mstats.kruskal(x, y)
  File "X:\Python35\lib\site-packages\scipy\stats\mstats_basic.py", line 1049, in kruskal
    H = 12./(ntot*(ntot+1)) * (sumrk**2/ngrp).sum() - 3*(ntot+1)
  File "X:\Python35\lib\site-packages\numpy\ma\core.py", line 3971, in __truediv__
    return true_divide(self, other)
  File "X:\Python35\lib\site-packages\numpy\ma\core.py", line 1118, in __call__
    result = self.f(da, db, *args, **kwargs)
ValueError: operands could not be broadcast together with shapes (2,) (2,5)

----------------------------------------------------------------------
Ran 23043 tests in 783.159s

FAILED (KNOWNFAIL=60, SKIP=1777, errors=1)

@charris
Copy link
Member

charris commented Jun 30, 2016

@cgohlke Done. I wasn't planning on another release of 1.11.x, but could do. Currently there are also some enhancements in that branch as well as this bug fix so it will need some testing time before a release. The release schedule needs some discussion.

@cgohlke
Copy link
Contributor

cgohlke commented Jun 30, 2016

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants