8000 ENH: Add an "axis" kwarg to numpy.unique by joferkington · Pull Request #3584 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add an "axis" kwarg to numpy.unique #3584

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

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
TST: Added basic tests for an invalid axis kwarg to unique
  • Loading branch information
joferkington committed Sep 25, 2013
commit d9ea28dabb4701ccd75fcf53fb891402587e42b2
19 changes: 11 additions & 8 deletions numpy/lib/tests/test_arraysetops.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,23 @@ def test_1d_functionality(self):
for dt in types:
aa = np.array(a, dt)
bb = np.array(b, dt)
self.run_1d_tests(aa, bb, i1, i2, dt)
self._run_1d_tests(aa, bb, i1, i2, dt)

# test for object arrays
dt = 'O'
aa = np.empty(len(a), dt)
aa[:] = a
bb = np.empty(len(b), dt)
bb[:] = b
self.run_1d_tests(aa, bb, i1, i2, dt)
self._run_1d_tests(aa, bb, i1, i2, dt)

# test for structured arrays
dt = [('', 'i'), ('', 'i')]
aa = np.array(list(zip(a, a)), dt)
bb = np.array(list(zip(b, b)), dt)
self.run_1d_tests(aa, bb, i1, i2, dt)
self._run_1d_tests(aa, bb, i1, i2, dt)

def run_1d_tests(self, a, b, i1, i2, dt):
def _run_1d_tests(self, a, b, i1, i2, dt):
msg = "check values failed for type '%s'" % dt
v = unique(a)
assert_array_equal(v, b, msg)
Expand All @@ -254,10 +254,13 @@ def run_1d_tests(self, a, b, i1, i2, dt):
assert_array_equal(j2, i2, msg)

def test_unique_axis_errors(self):
assert_raises(TypeError, self.run_axis_tests, object)
assert_raises(TypeError, self.run_axis_tests,
assert_raises(TypeError, self._run_axis_tests, object)
assert_raises(TypeError, self._run_axis_tests,
[('a', int), ('b', object)])

assert_raises(ValueError, unique, np.arange(10), axis=2)
assert_raises(ValueError, unique, np.arange(10), axis=-2)

def test_unique_axis(self):
types = []
types.extend(np.typecodes['AllInteger'])
Expand All @@ -268,7 +271,7 @@ def test_unique_axis(self):
types.append([('a', int), ('b', float)])

for dtype in types:
self.run_axis_tests(dtype)
self._run_axis_tests(dtype)

msg = 'Non-bitwise-equal booleans test failed'
data = np.arange(10, dtype=np.uint8).reshape(-1, 2).view(bool)
Expand All @@ -280,7 +283,7 @@ def test_unique_axis(self):
result = np.array([[-0.0, 0.0]])
assert_array_equal(unique(data, axis=0), result, msg)

def run_axis_tests(self, dtype):
def _run_axis_tests(self, dtype):
data = np.array([[0, 1, 0, 0],
[1, 0, 0, 0],
[0, 1, 0, 0],
Expand Down
0