Skip to content

Commit e5f5275

Browse files
committed
Do not attempt to access empty data. Fixes #290.
1 parent 94be739 commit e5f5275

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: src/blosc2/blosc2_ext.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ cdef class SChunk:
10101010
cdef int64_t index
10111011
cdef Py_buffer *buf
10121012
cdef uint8_t *buf_ptr
1013-
if data is not None:
1013+
if data is not None and len(data) > 0:
10141014
buf = <Py_buffer *> malloc(sizeof(Py_buffer))
10151015
PyObject_GetBuffer(data, buf, PyBUF_SIMPLE)
10161016
buf_ptr = <uint8_t *> buf.buf

Diff for: tests/test_tensor.py

+10
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ def test_pack_tensor_array(size, dtype):
128128
assert np.array_equal(nparray, a2)
129129

130130

131+
def test_pack_tensor_empty():
132+
empty = np.zeros((0,), dtype=float)
133+
pempty = blosc2.pack_tensor(empty)
134+
135+
empty2 = blosc2.unpack_tensor(pempty)
136+
assert np.array_equal(empty, empty2)
137+
assert empty2.dtype == empty.dtype
138+
assert empty2.shape == empty.shape
139+
140+
131141
##### save / load #####
132142

133143

0 commit comments

Comments
 (0)