From 98e28b8674626cd5e946df18fc896cdcdc04ed52 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 9 Nov 2018 16:10:17 -0500 Subject: [PATCH 1/2] Use `buffer_tobytes` on non-`object` types in test When running the `check_backwards_compatibility` test, make sure not to call `buffer_tobytes` on `object` arrays from fixture data. Casting these to bytes doesn't really make sense as it will return representation of pointers in the underlying buffer. Not only are the pointers things we do not want to be comparing, but it is also internal spec to NumPy and Python that really isn't reliable either. So make sure to pass through the `object` arrays as is. --- numcodecs/tests/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numcodecs/tests/common.py b/numcodecs/tests/common.py index 0e61e418..2cd90cc3 100644 --- a/numcodecs/tests/common.py +++ b/numcodecs/tests/common.py @@ -187,7 +187,8 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref # setup i = int(arr_fn.split('.')[-2]) arr = np.load(arr_fn) - arr_bytes = buffer_tobytes(arr) + if arr.dtype.kind is not 'O': + arr_bytes = buffer_tobytes(arr) if arr.flags.f_contiguous: order = 'F' else: From 1d2fbf5a744cf9b2bda477ef914375c10f82af8f Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Fri, 9 Nov 2018 17:23:58 -0500 Subject: [PATCH 2/2] Coerce buffer to bytes only when it is needed --- numcodecs/tests/common.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/numcodecs/tests/common.py b/numcodecs/tests/common.py index 2cd90cc3..6e6a20d1 100644 --- a/numcodecs/tests/common.py +++ b/numcodecs/tests/common.py @@ -187,8 +187,6 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref # setup i = int(arr_fn.split('.')[-2]) arr = np.load(arr_fn) - if arr.dtype.kind is not 'O': - arr_bytes = buffer_tobytes(arr) if arr.flags.f_contiguous: order = 'F' else: @@ -234,7 +232,7 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref assert_array_items_equal(arr, dec_arr) else: assert_array_equal(arr, dec_arr) - assert arr_bytes == buffer_tobytes(dec) + assert buffer_tobytes(arr) == buffer_tobytes(dec) def check_err_decode_object_buffer(compressor):