Skip to content

Commit f934052

Browse files
ivirshuprabernat
andauthored
Allow VLenUTF8 to encode a read-only source (#515)
* fix? * test * format * add release notes --------- Co-authored-by: Ryan Abernathey <[email protected]>
1 parent 1be12d3 commit f934052

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

docs/release.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Enhancements
2626

2727
Fix
2828
~~~
29-
29+
* Fix VLenUTF8 encoding for read-only buffers.
30+
By :user:`Isaac Virshup <ivirshup>`, :issue:`514`.
3031
* Fix skip of entry points backport tests
3132
By :user:`Elliott Sales de Andrade <QuLogic>`, :issue:`487`.
3233
* Fix Upgrade to Zstd 1.5.5 due to potential corruption.

numcodecs/tests/test_vlen_utf8.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ def test_decode_errors():
8282
codec.decode(enc, out=np.zeros(10, dtype='i4'))
8383

8484

85-
def test_encode_utf8():
85+
@pytest.mark.parametrize("writable", [True, False])
86+
def test_encode_utf8(writable):
8687
a = np.array(['foo', None, 'bar'], dtype=object)
88+
if not writable:
89+
a.setflags(write=False)
8790
codec = VLenUTF8()
8891
enc = codec.encode(a)
8992
dec = codec.decode(enc)

numcodecs/vlen.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import cython
99
cimport cython
10+
from numpy cimport ndarray
1011
import numpy as np
1112
from .abc import Codec
1213
from .compat_ext cimport Buffer
@@ -74,7 +75,7 @@ class VLenUTF8(Codec):
7475
def encode(self, buf):
7576
cdef:
7677
Py_ssize_t i, l, n_items, data_length, total_length
77-
object[:] input_values
78+
ndarray[object, ndim=1] input_values
7879
object[:] encoded_values
7980
int[:] encoded_lengths
8081
char* encv

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ requires = [
33
"setuptools>=64",
44
"setuptools-scm[toml]>=6.2",
55
"Cython",
6-
"py-cpuinfo"
6+
"py-cpuinfo",
7+
"numpy",
78
]
89
build-backend = "setuptools.build_meta"
910

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ def lz4_extension():
196196

197197
def vlen_extension():
198198
info('setting up vlen extension')
199+
import numpy
199200

200201
extra_compile_args = base_compile_args.copy()
201202
define_macros = []
202203

203204
# setup sources
204-
include_dirs = ['numcodecs']
205+
include_dirs = ['numcodecs', numpy.get_include()]
205206
# define_macros += [('CYTHON_TRACE', '1')]
206207

207208
sources = ['numcodecs/vlen.pyx']

0 commit comments

Comments
 (0)