Exemple #1
0
 def test_read_blosc(self, array, stream):
     array = np.asanyarray(array)
     stream.seek(0)
     out = read_blosc(stream)
     assert out.shape == array.shape
     assert out.dtype == array.dtype
     np.testing.assert_array_equal(out, array)
Exemple #2
0
 def test_recarray(self):
     arr = np.rec.fromarrays(np.arange(6).reshape(2, 3), names='x, y').view(np.recarray)
     assert arr.dtype.type is np.record
     stream = io.BytesIO()
     write_blosc(stream, arr)
     stream.seek(0)
     out = read_blosc(stream)
     assert isinstance(out, np.recarray)
     assert out.dtype == arr.dtype
     assert out.dtype.type is np.record
Exemple #3
0
 def read(self, key, out=None):
     self._check_handle()
     self._check_key(key)
     is_array, offset = self._index[key]
     if not is_array and out is not None:
         raise ValueError('can only specify output for array values')
     self._handle.seek(offset)
     if is_array:
         return read_blosc(self._handle, out=out)
     else:
         return read_json(self._handle)
Exemple #4
0
    def test_read_into(self, array, stream):
        array = np.asanyarray(array)

        stream.seek(0)
        pytest.raises_regexp(TypeError, 'expected ndarray', read_blosc, stream,
                             out='foo')
        stream.seek(0)
        pytest.raises_regexp(ValueError, 'incompatible shape', read_blosc, stream,
                             out=np.empty((42, 42)))
        stream.seek(0)
        pytest.raises_regexp(ValueError, 'incompatible dtype', read_blosc, stream,
                             out=np.empty(array.shape, np.uint8))

        if array.ndim == 3:
            out = np.empty_like(array.transpose(0, 2, 1), order='F').transpose(0, 2, 1)
            stream.seek(0)
            pytest.raises_regexp(ValueError, 'expected contiguous array', read_blosc, stream,
                                 out=out)

        out = np.empty_like(array)
        stream.seek(0)
        assert read_blosc(stream, out=out) is out
        stream.seek(0)
        np.testing.assert_array_equal(out, read_blosc(stream))