diff --git a/docs/release.rst b/docs/release.rst index b569015c..17f146e9 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -26,7 +26,8 @@ Enhancements Fix ~~~ - +* Fix VLenUTF8 encoding for read-only buffers. + By :user:`Isaac Virshup `, :issue:`514`. * Fix skip of entry points backport tests By :user:`Elliott Sales de Andrade `, :issue:`487`. * Fix Upgrade to Zstd 1.5.5 due to potential corruption. diff --git a/numcodecs/tests/test_vlen_utf8.py b/numcodecs/tests/test_vlen_utf8.py index c2ee525b..4501d929 100644 --- a/numcodecs/tests/test_vlen_utf8.py +++ b/numcodecs/tests/test_vlen_utf8.py @@ -82,8 +82,11 @@ def test_decode_errors(): codec.decode(enc, out=np.zeros(10, dtype='i4')) -def test_encode_utf8(): +@pytest.mark.parametrize("writable", [True, False]) +def test_encode_utf8(writable): a = np.array(['foo', None, 'bar'], dtype=object) + if not writable: + a.setflags(write=False) codec = VLenUTF8() enc = codec.encode(a) dec = codec.decode(enc) diff --git a/numcodecs/vlen.pyx b/numcodecs/vlen.pyx index a1ff0e26..e1e149ee 100644 --- a/numcodecs/vlen.pyx +++ b/numcodecs/vlen.pyx @@ -7,6 +7,7 @@ import cython cimport cython +from numpy cimport ndarray import numpy as np from .abc import Codec from .compat_ext cimport Buffer @@ -74,7 +75,7 @@ class VLenUTF8(Codec): def encode(self, buf): cdef: Py_ssize_t i, l, n_items, data_length, total_length - object[:] input_values + ndarray[object, ndim=1] input_values object[:] encoded_values int[:] encoded_lengths char* encv diff --git a/pyproject.toml b/pyproject.toml index 319b29d7..af8f040a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,8 @@ requires = [ "setuptools>=64", "setuptools-scm[toml]>=6.2", "Cython", - "py-cpuinfo" + "py-cpuinfo", + "numpy", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index ea8bc64c..e594a203 100644 --- a/setup.py +++ b/setup.py @@ -196,12 +196,13 @@ def lz4_extension(): def vlen_extension(): info('setting up vlen extension') + import numpy extra_compile_args = base_compile_args.copy() define_macros = [] # setup sources - include_dirs = ['numcodecs'] + include_dirs = ['numcodecs', numpy.get_include()] # define_macros += [('CYTHON_TRACE', '1')] sources = ['numcodecs/vlen.pyx']