Skip to content

Commit 8e51103

Browse files
committed
various fixes; use pytest
1 parent 7e9e867 commit 8e51103

File tree

13 files changed

+1438
-1537
lines changed

13 files changed

+1438
-1537
lines changed

numcodecs/blosc.c

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

numcodecs/categorize.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
from .abc import Codec
6-
from .compat import ndarray_from_buffer, buffer_copy, ensure_text, ensure_bytes
6+
from .compat import ndarray_from_buffer, buffer_copy, ensure_text
77

88

99
import numpy as np
@@ -25,18 +25,18 @@ class Categorize(Codec):
2525
--------
2626
>>> import numcodecs
2727
>>> import numpy as np
28-
>>> x = np.array([b'male', b'female', b'female', b'male', b'unexpected'])
28+
>>> x = np.array(['male', 'female', 'female', 'male', 'unexpected'], dtype=object)
2929
>>> x
30-
array([b'male', b'female', b'female', b'male', b'unexpected'],
31-
dtype='|S10')
32-
>>> codec = numcodecs.Categorize(labels=[b'female', b'male'], dtype=x.dtype)
30+
array(['male', 'female', 'female', 'male', 'unexpected'],
31+
dtype=object)
32+
>>> codec = numcodecs.Categorize(labels=['female', 'male'], dtype=object)
3333
>>> y = codec.encode(x)
3434
>>> y
3535
array([2, 1, 1, 2, 0], dtype=uint8)
3636
>>> z = codec.decode(y)
3737
>>> z
38-
array([b'male', b'female', b'female', b'male', b''],
39-
dtype='|S10')
38+
array(['male', 'female', 'female', 'male', ''],
39+
dtype=object)
4040
4141
"""
4242

numcodecs/compat.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,6 @@ def buffer_copy(buf, out=None):
8585
return out
8686

8787

88-
# def buffer_size(v):
89-
# from array import array as _stdlib_array
90-
# if PY2 and isinstance(v, _stdlib_array): # pragma: no cover
91-
# # special case array.array because does not support buffer
92-
# # interface in PY2
93-
# return v.buffer_info()[1] * v.itemsize
94-
# else:
95-
# v = memoryview(v)
96-
# return reduce(operator.mul, v.shape) * v.itemsize
97-
98-
9988
def ndarray_from_buffer(buf, dtype):
10089
if isinstance(buf, np.ndarray):
10190
arr = buf.reshape(-1, order='A').view(dtype)
@@ -104,17 +93,10 @@ def ndarray_from_buffer(buf, dtype):
10493
return arr
10594

10695

107-
def ensure_bytes(l, encoding='utf-8'):
108-
if isinstance(l, binary_type):
109-
return l
110-
else:
111-
return l.encode(encoding=encoding)
112-
113-
11496
def ensure_text(l, encoding='utf-8'):
11597
if isinstance(l, text_type):
11698
return l
117-
else:
99+
else: # pragma: py3 no cover
118100
return text_type(l, encoding=encoding)
119101

120102

numcodecs/compat_ext.c

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

numcodecs/lz4.c

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

numcodecs/tests/test_categorize.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66
from numpy.testing import assert_array_equal
7-
from nose.tools import eq_ as eq
7+
from nose.tools import assert_raises
88

99

1010
from numcodecs.categorize import Categorize
@@ -51,14 +51,14 @@ def test_encode():
5151
expect = np.array([1, 2, 1, 3, 0], dtype='u1')
5252
enc = codec.encode(arr)
5353
assert_array_equal(expect, enc)
54-
eq(expect.dtype, enc.dtype)
54+
assert expect.dtype == enc.dtype
5555

5656
# test decoding with unexpected value
5757
dec = codec.decode(enc)
5858
expect = arr.copy()
5959
expect[expect == u'ƪùüx'] = u''
6060
assert_array_equal(expect, dec)
61-
eq(arr.dtype, dec.dtype)
61+
assert arr.dtype == dec.dtype
6262

6363

6464
def test_config():
@@ -77,7 +77,7 @@ def test_repr():
7777
else: # pragma: py2 no cover
7878
expect += "labels=['foo', 'bar', 'baz', ...])"
7979
actual = repr(codec)
80-
eq(expect, actual)
80+
assert expect == actual
8181

8282
if not PY2: # pragma: py2 no cover
8383

@@ -87,7 +87,7 @@ def test_repr():
8787
expect = "Categorize(dtype='<U4', astype='|u1', " \
8888
"labels=['ƒöõ', 'ßàř', 'ßāẑ', ...])"
8989
actual = repr(codec)
90-
eq(expect, actual)
90+
assert expect == actual
9191

9292

9393
def test_backwards_compatibility():
@@ -97,3 +97,8 @@ def test_backwards_compatibility():
9797
codec = Categorize(labels=labels, dtype=object, astype='u1')
9898
check_backwards_compatibility(Categorize.codec_id, arrays_object,
9999
[codec], prefix='O')
100+
101+
102+
def test_errors():
103+
with assert_raises(ValueError):
104+
Categorize(labels=['foo', 'bar'], dtype='S6')

0 commit comments

Comments
 (0)