Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release notes
=============

.. _release_0.5.2:

0.5.2
-----

* Add support for encoding None values in VLen... codecs (:issue:`59`).

.. _release_0.5.1:

0.5.1
Expand Down
17 changes: 15 additions & 2 deletions numcodecs/tests/test_vlen_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from numcodecs.vlen import VLenArray
except ImportError: # pragma: no cover
raise nose.SkipTest("vlen-array not available")
from numcodecs.tests.common import (check_config, check_repr, check_encode_decode_array,
check_backwards_compatibility)
from numcodecs.tests.common import (check_config, check_repr,
check_encode_decode_array,
check_backwards_compatibility,
assert_array_items_equal)


arrays = [
Expand Down Expand Up @@ -88,3 +90,14 @@ def test_decode_errors():
codec.decode(enc, out=123)
with assert_raises(ValueError):
codec.decode(enc, out=np.zeros(10, dtype='i4'))


def test_encode_none():
a = np.array([[1, 3], None, [4, 7]], dtype=object)
codec = VLenArray(int)
enc = codec.encode(a)
dec = codec.decode(enc)
expect = np.array([np.array([1, 3]),
np.array([]),
np.array([4, 7])], dtype=object)
assert_array_items_equal(expect, dec)
14 changes: 12 additions & 2 deletions numcodecs/tests/test_vlen_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
except ImportError: # pragma: no cover
raise nose.SkipTest("vlen-bytes not available")
from numcodecs.tests.common import (check_config, check_repr, check_encode_decode_array,
check_backwards_compatibility, greetings)
check_backwards_compatibility, greetings,
assert_array_items_equal)


greetings_bytes = [g.encode('utf-8') for g in greetings]
Expand Down Expand Up @@ -53,7 +54,7 @@ def test_encode_errors():
with assert_raises(TypeError):
codec.encode([1234, 5678])
with assert_raises(TypeError):
codec.encode(np.zeros(10, dtype='i4'))
codec.encode(np.ones(10, dtype='i4'))


def test_decode_errors():
Expand All @@ -80,3 +81,12 @@ def test_decode_errors():
codec.decode(enc, out=123)
with assert_raises(ValueError):
codec.decode(enc, out=np.zeros(10, dtype='i4'))


def test_encode_none():
a = np.array([b'foo', None, b'bar'], dtype=object)
codec = VLenBytes()
enc = codec.encode(a)
dec = codec.decode(enc)
expect = np.array([b'foo', b'', b'bar'], dtype=object)
assert_array_items_equal(expect, dec)
14 changes: 12 additions & 2 deletions numcodecs/tests/test_vlen_utf8.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
except ImportError: # pragma: no cover
raise nose.SkipTest("vlen-utf8 not available")
from numcodecs.tests.common import (check_config, check_repr, check_encode_decode_array,
check_backwards_compatibility, greetings)
check_backwards_compatibility, greetings,
assert_array_items_equal)


arrays = [
Expand Down Expand Up @@ -49,7 +50,7 @@ def test_encode_errors():
with assert_raises(TypeError):
codec.encode([1234, 5678])
with assert_raises(TypeError):
codec.encode(np.zeros(10, dtype='i4'))
codec.encode(np.ones(10, dtype='i4'))


def test_decode_errors():
Expand All @@ -76,3 +77,12 @@ def test_decode_errors():
codec.decode(enc, out=123)
with assert_raises(ValueError):
codec.decode(enc, out=np.zeros(10, dtype='i4'))


def test_encode_utf8():
a = np.array([u'foo', None, u'bar'], dtype=object)
codec = VLenUTF8()
enc = codec.encode(a)
dec = codec.decode(enc)
expect = np.array([u'foo', u'', u'bar'], dtype=object)
assert_array_items_equal(expect, dec)
Loading