Skip to content

Commit dbb4667

Browse files
committed
test and fix None for all vlen codecs
1 parent b2f0b81 commit dbb4667

File tree

5 files changed

+1678
-1422
lines changed

5 files changed

+1678
-1422
lines changed

numcodecs/tests/test_vlen_bytes.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
except ImportError: # pragma: no cover
1313
raise nose.SkipTest("vlen-bytes not available")
1414
from numcodecs.tests.common import (check_config, check_repr, check_encode_decode_array,
15-
check_backwards_compatibility, greetings)
15+
check_backwards_compatibility, greetings,
16+
assert_array_items_equal)
1617

1718

1819
greetings_bytes = [g.encode('utf-8') for g in greetings]
@@ -53,7 +54,7 @@ def test_encode_errors():
5354
with assert_raises(TypeError):
5455
codec.encode([1234, 5678])
5556
with assert_raises(TypeError):
56-
codec.encode(np.zeros(10, dtype='i4'))
57+
codec.encode(np.ones(10, dtype='i4'))
5758

5859

5960
def test_decode_errors():
@@ -80,3 +81,12 @@ def test_decode_errors():
8081
codec.decode(enc, out=123)
8182
with assert_raises(ValueError):
8283
codec.decode(enc, out=np.zeros(10, dtype='i4'))
84+
85+
86+
def test_encode_none():
87+
a = np.array([b'foo', None, b'bar'], dtype=object)
88+
codec = VLenBytes()
89+
enc = codec.encode(a)
90+
dec = codec.decode(enc)
91+
expect = np.array([b'foo', b'', b'bar'], dtype=object)
92+
assert_array_items_equal(expect, dec)

numcodecs/tests/test_vlen_utf8.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
except ImportError: # pragma: no cover
1313
raise nose.SkipTest("vlen-utf8 not available")
1414
from numcodecs.tests.common import (check_config, check_repr, check_encode_decode_array,
15-
check_backwards_compatibility, greetings)
15+
check_backwards_compatibility, greetings,
16+
assert_array_items_equal)
1617

1718

1819
arrays = [
@@ -49,7 +50,7 @@ def test_encode_errors():
4950
with assert_raises(TypeError):
5051
codec.encode([1234, 5678])
5152
with assert_raises(TypeError):
52-
codec.encode(np.zeros(10, dtype='i4'))
53+
codec.encode(np.ones(10, dtype='i4'))
5354

5455

5556
def test_decode_errors():
@@ -76,3 +77,12 @@ def test_decode_errors():
7677
codec.decode(enc, out=123)
7778
with assert_raises(ValueError):
7879
codec.decode(enc, out=np.zeros(10, dtype='i4'))
80+
81+
82+
def test_encode_utf8():
83+
a = np.array(['foo', None, 'bar'], dtype=object)
84+
codec = VLenUTF8()
85+
enc = codec.encode(a)
86+
dec = codec.decode(enc)
87+
expect = np.array(['foo', '', 'bar'], dtype=object)
88+
assert_array_items_equal(expect, dec)

0 commit comments

Comments
 (0)