From 546e56054e2139cf57dab9b83e793020cd7f2e13 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 30 Nov 2018 15:48:15 -0500 Subject: [PATCH 1/3] Ensure `VLen*` `encode` methods return `ndarray`s There were a few `VLen*` types that were missed by the previous PR that ensured the `encode` methods all returned `ndarray`s. In particular `VLenBytes` and `VLenArray` were missed. This fixes that oversight by ensuring these also return `ndarray`s. --- numcodecs/vlen.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numcodecs/vlen.pyx b/numcodecs/vlen.pyx index 5cc90490..02c4cdde 100644 --- a/numcodecs/vlen.pyx +++ b/numcodecs/vlen.pyx @@ -258,7 +258,7 @@ class VLenBytes(Codec): memcpy(data, encv, l) data += l - return out + return ensure_ndarray(out) @cython.wraparound(False) @cython.boundscheck(False) @@ -405,7 +405,7 @@ class VLenArray(Codec): data += l value_buffer.release() - return out + return ensure_ndarray(out) @cython.wraparound(False) @cython.boundscheck(False) From 554d4c12d1308afa2ead6d32b59ca65f00fce990 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 30 Nov 2018 15:48:16 -0500 Subject: [PATCH 2/3] Regenerate C code from Cython code As there were some changes made to `vlen.pyx`, have Cython regenerate `vlen.c` to include the relevant changes. --- numcodecs/vlen.c | 50 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/numcodecs/vlen.c b/numcodecs/vlen.c index 06ec4314..6163b905 100644 --- a/numcodecs/vlen.c +++ b/numcodecs/vlen.c @@ -4315,7 +4315,7 @@ static PyObject *__pyx_pf_9numcodecs_4vlen_9VLenBytes_2encode(CYTHON_UNUSED PyOb * memcpy(data, encv, l) * data += l # <<<<<<<<<<<<<< * - * return out + * return ensure_ndarray(out) */ __pyx_v_data = (__pyx_v_data + __pyx_v_l); } @@ -4323,13 +4323,30 @@ static PyObject *__pyx_pf_9numcodecs_4vlen_9VLenBytes_2encode(CYTHON_UNUSED PyOb /* "numcodecs/vlen.pyx":261 * data += l * - * return out # <<<<<<<<<<<<<< + * return ensure_ndarray(out) # <<<<<<<<<<<<<< * * @cython.wraparound(False) */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_out); - __pyx_r = __pyx_v_out; + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_ensure_ndarray); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 261, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_v_out) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_out); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 261, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; /* "numcodecs/vlen.pyx":212 @@ -5808,7 +5825,7 @@ static PyObject *__pyx_pf_9numcodecs_4vlen_9VLenArray_6encode(CYTHON_UNUSED PyOb * data += l * value_buffer.release() # <<<<<<<<<<<<<< * - * return out + * return ensure_ndarray(out) */ __pyx_t_1 = ((struct __pyx_vtabstruct_9numcodecs_10compat_ext_Buffer *)__pyx_v_value_buffer->__pyx_vtab)->release(__pyx_v_value_buffer, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -5818,13 +5835,30 @@ static PyObject *__pyx_pf_9numcodecs_4vlen_9VLenArray_6encode(CYTHON_UNUSED PyOb /* "numcodecs/vlen.pyx":408 * value_buffer.release() * - * return out # <<<<<<<<<<<<<< + * return ensure_ndarray(out) # <<<<<<<<<<<<<< * * @cython.wraparound(False) */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_out); - __pyx_r = __pyx_v_out; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ensure_ndarray); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 408, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_out) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_out); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 408, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; /* "numcodecs/vlen.pyx":350 From 8b141025098b63d98f08ce8da69daabe48e31439 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 30 Nov 2018 16:10:37 -0500 Subject: [PATCH 3/3] Document VLen encode change in release notes [ci skip] --- docs/release.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/release.rst b/docs/release.rst index c55df95b..a063ef4b 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -1,6 +1,15 @@ Release notes ============= +.. _release_0.6.2: + +0.6.2 +----- + +* Fix other ``VLen*`` encode() methods to return numpy arrays as well. + By :user:`John Kirkham `, :issue:`144`. + + .. _release_0.6.1: 0.6.1