zarr-developers / numcodecs

A Python package providing buffer compression and transformation codecs for use in data storage and communication applications.
http://numcodecs.readthedocs.io
MIT License
125 stars 87 forks source link

Blosc throws floating point exception when encoding NumPy array with zero-itemsize dtype #516

Open li-dan opened 6 months ago

li-dan commented 6 months ago

Minimal, reproducible code sample, a copy-pastable example if possible

import numcodecs, numpy; numcodecs.Blosc().encode(numpy.zeros((5,), dtype=[('foo', int, (0,))]))

Problem description

This throws a floating point exception:

$ python -c "import numcodecs, numpy; numcodecs.Blosc().encode(numpy.zeros((5,), dtype=[('foo', int, (0,))]))"
Floating point exception (core dumped)

The expected output is that the array is encoded without an exception.

The array has ndarray.nbytes=0 and ndarray.dtype.itemsize=0. NumCodecs passes these into Blosc, and eventually compute_blocksize gets called with typesize=0 and nbytes=0, causing compute_blocksize to return 0. This triggers a floating point exception on this line in initialize_context_compression().

Version and installation information