summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_packbits.py
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2019-03-13 10:05:40 +0200
committermattip <matti.picus@gmail.com>2019-05-11 16:07:27 -0700
commitb415ffad5327c5ff656b94c6aaf683209c9c8104 (patch)
tree746dd770902e2fd30035bad43bba68f379f9154b /numpy/lib/tests/test_packbits.py
parent8c4d4bb73e5bd69a7961a912fffc38c6a49d6bf2 (diff)
downloadnumpy-b415ffad5327c5ff656b94c6aaf683209c9c8104.tar.gz
ENH: changes from review
Diffstat (limited to 'numpy/lib/tests/test_packbits.py')
-rw-r--r--numpy/lib/tests/test_packbits.py54
1 files changed, 29 insertions, 25 deletions
diff --git a/numpy/lib/tests/test_packbits.py b/numpy/lib/tests/test_packbits.py
index d6e96f3ea..95a465c36 100644
--- a/numpy/lib/tests/test_packbits.py
+++ b/numpy/lib/tests/test_packbits.py
@@ -51,8 +51,8 @@ def test_packbits_empty_with_axis():
assert_equal(b.dtype, np.uint8)
assert_equal(b.shape, out_shape)
-@pytest.mark.parametrize('order', ('l', 'b'))
-def test_packbits_large(order):
+@pytest.mark.parametrize('bitorder', ('little', 'big'))
+def test_packbits_large(bitorder):
# test data large enough for 16 byte vectorization
a = np.array([1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0,
0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1,
@@ -72,7 +72,7 @@ def test_packbits_large(order):
a = a.repeat(3)
for dtype in '?bBhHiIlLqQ':
arr = np.array(a, dtype=dtype)
- b = np.packbits(arr, axis=None, order=order)
+ b = np.packbits(arr, axis=None, bitorder=bitorder)
assert_equal(b.dtype, np.uint8)
r = [252, 127, 192, 3, 254, 7, 252, 0, 7, 31, 240, 0, 28, 1, 255, 252,
113, 248, 3, 255, 192, 28, 15, 192, 28, 126, 0, 224, 127, 255,
@@ -82,10 +82,10 @@ def test_packbits_large(order):
255, 224, 1, 255, 252, 126, 63, 0, 1, 192, 252, 14, 63, 0, 15,
199, 252, 113, 255, 3, 128, 56, 252, 14, 7, 0, 113, 255, 255, 142, 56, 227,
129, 248, 227, 129, 199, 31, 128]
- if order == 'big':
+ if bitorder == 'big':
assert_array_equal(b, r)
# equal for size being multiple of 8
- assert_array_equal(np.unpackbits(b, order=order)[:-4], a)
+ assert_array_equal(np.unpackbits(b, bitorder=bitorder)[:-4], a)
# check last byte of different remainders (16 byte vectorization)
b = [np.packbits(arr[:-i], axis=None)[-1] for i in range(1, 16)]
@@ -235,14 +235,14 @@ def test_pack_unpack_order():
a = np.array([[2], [7], [23]], dtype=np.uint8)
b = np.unpackbits(a, axis=1)
assert_equal(b.dtype, np.uint8)
- b_little = np.unpackbits(a, axis=1, order='little')
- b_big = np.unpackbits(a, axis=1, order='big')
+ b_little = np.unpackbits(a, axis=1, bitorder='little')
+ b_big = np.unpackbits(a, axis=1, bitorder='big')
assert_array_equal(b, b_big)
- assert_array_equal(a, np.packbits(b_little, axis=1, order='little'))
+ assert_array_equal(a, np.packbits(b_little, axis=1, bitorder='little'))
assert_array_equal(b[:,::-1], b_little)
- assert_array_equal(a, np.packbits(b_big, axis=1, order='big'))
- assert_raises(ValueError, np.unpackbits, a, order='r')
- assert_raises(TypeError, np.unpackbits, a, order=10)
+ assert_array_equal(a, np.packbits(b_big, axis=1, bitorder='big'))
+ assert_raises(ValueError, np.unpackbits, a, bitorder='r')
+ assert_raises(TypeError, np.unpackbits, a, bitorder=10)
@@ -301,17 +301,17 @@ class TestCount():
padded2 = np.zeros((9, 9), dtype=np.uint8)
padded2[:7, :7] = x
- @pytest.mark.parametrize('order', ('l', 'b'))
+ @pytest.mark.parametrize('bitorder', ('little', 'big'))
@pytest.mark.parametrize('count', chain(range(58), range(-1, -57, -1)))
- def test_roundtrip(self, order, count):
+ def test_roundtrip(self, bitorder, count):
if count < 0:
# one extra zero of padding
cutoff = count - 1
else:
cutoff = count
# test complete invertibility of packbits and unpackbits with count
- packed = np.packbits(self.x, order=order)
- unpacked = np.unpackbits(packed, count=count, order=order)
+ packed = np.packbits(self.x, bitorder=bitorder)
+ unpacked = np.unpackbits(packed, count=count, bitorder=bitorder)
assert_equal(unpacked.dtype, np.uint8)
assert_array_equal(unpacked, self.padded1[:cutoff])
@@ -324,35 +324,39 @@ class TestCount():
assert_equal(unpacked.dtype, np.uint8)
assert_array_equal(unpacked, self.padded1[:-1])
- @pytest.mark.parametrize('order', ('l', 'b'))
+ @pytest.mark.parametrize('bitorder', ('little', 'big'))
# delta==-1 when count<0 because one extra zero of padding
@pytest.mark.parametrize('count', chain(range(8), range(-1, -9, -1)))
- def test_roundtrip_axis(self, order, count):
+ def test_roundtrip_axis(self, bitorder, count):
if count < 0:
# one extra zero of padding
cutoff = count - 1
else:
cutoff = count
- packed0 = np.packbits(self.x, axis=0, order=order)
- unpacked0 = np.unpackbits(packed0, axis=0, count=count, order=order)
+ packed0 = np.packbits(self.x, axis=0, bitorder=bitorder)
+ unpacked0 = np.unpackbits(packed0, axis=0, count=count,
+ bitorder=bitorder)
assert_equal(unpacked0.dtype, np.uint8)
assert_array_equal(unpacked0, self.padded2[:cutoff, :self.x.shape[1]])
- packed1 = np.packbits(self.x, axis=1, order=order)
- unpacked1 = np.unpackbits(packed1, axis=1, count=count, order=order)
+ packed1 = np.packbits(self.x, axis=1, bitorder=bitorder)
+ unpacked1 = np.unpackbits(packed1, axis=1, count=count,
+ bitorder=bitorder)
assert_equal(unpacked1.dtype, np.uint8)
assert_array_equal(unpacked1, self.padded2[:self.x.shape[0], :cutoff])
@pytest.mark.parametrize('kwargs', [
{}, {'count': None},
- {'order' : 'l'}, {'order': 'l', 'count': None},
- {'order' : 'b'}, {'order': 'b', 'count': None},
+ {'bitorder' : 'little'},
+ {'bitorder': 'little', 'count': None},
+ {'bitorder' : 'big'},
+ {'bitorder': 'big', 'count': None},
])
def test_axis_count(self, kwargs):
packed0 = np.packbits(self.x, axis=0)
unpacked0 = np.unpackbits(packed0, axis=0, **kwargs)
assert_equal(unpacked0.dtype, np.uint8)
- if kwargs.get('order', 'b') == 'b':
+ if kwargs.get('bitorder', 'big') == 'big':
assert_array_equal(unpacked0, self.padded2[:-1, :self.x.shape[1]])
else:
assert_array_equal(unpacked0[::-1, :], self.padded2[:-1, :self.x.shape[1]])
@@ -360,7 +364,7 @@ class TestCount():
packed1 = np.packbits(self.x, axis=1)
unpacked1 = np.unpackbits(packed1, axis=1, **kwargs)
assert_equal(unpacked1.dtype, np.uint8)
- if kwargs.get('order', 'b') == 'b':
+ if kwargs.get('bitorder', 'big') == 'big':
assert_array_equal(unpacked1, self.padded2[:self.x.shape[0], :-1])
else:
assert_array_equal(unpacked1[:, ::-1], self.padded2[:self.x.shape[0], :-1])