|
3 | 3 | import unittest
|
4 | 4 | from tempfile import mkdtemp, mktemp
|
5 | 5 | import atexit
|
| 6 | +import json |
6 | 7 | import shutil
|
7 | 8 | import pickle
|
8 | 9 | import os
|
|
20 | 21 | from zarr.core import Array
|
21 | 22 | from zarr.errors import PermissionError
|
22 | 23 | from zarr.compat import PY2, text_type, binary_type, zip_longest
|
| 24 | +from zarr.meta import ensure_str |
23 | 25 | from zarr.util import buffer_size
|
24 |
| -from numcodecs import (Delta, FixedScaleOffset, Zlib, Blosc, BZ2, MsgPack, Pickle, |
| 26 | +from numcodecs import (Delta, FixedScaleOffset, LZ4, GZip, Zlib, Blosc, BZ2, MsgPack, Pickle, |
25 | 27 | Categorize, JSON, VLenUTF8, VLenBytes, VLenArray)
|
26 | 28 | from numcodecs.compat import ensure_bytes, ensure_ndarray
|
27 | 29 | from numcodecs.tests.common import greetings
|
@@ -1215,6 +1217,39 @@ def test_iter(self):
|
1215 | 1217 | for expect, actual in zip_longest(a, z):
|
1216 | 1218 | assert_array_equal(expect, actual)
|
1217 | 1219 |
|
| 1220 | + def test_compressors(self): |
| 1221 | + compressors = [ |
| 1222 | + None, BZ2(), Blosc(), LZ4(), Zlib(), GZip() |
| 1223 | + ] |
| 1224 | + if LZMA: |
| 1225 | + compressors.append(LZMA()) |
| 1226 | + for compressor in compressors: |
| 1227 | + a = self.create_array(shape=1000, chunks=100, compressor=compressor) |
| 1228 | + a[0:100] = 1 |
| 1229 | + assert np.all(a[0:100] == 1) |
| 1230 | + a[:] = 1 |
| 1231 | + assert np.all(a[:] == 1) |
| 1232 | + |
| 1233 | + def test_endian(self): |
| 1234 | + dtype = np.dtype('float32') |
| 1235 | + a1 = self.create_array(shape=1000, chunks=100, dtype=dtype.newbyteorder('<')) |
| 1236 | + a1[:] = 1 |
| 1237 | + x1 = a1[:] |
| 1238 | + a2 = self.create_array(shape=1000, chunks=100, dtype=dtype.newbyteorder('>')) |
| 1239 | + a2[:] = 1 |
| 1240 | + x2 = a2[:] |
| 1241 | + assert_array_equal(x1, x2) |
| 1242 | + |
| 1243 | + def test_attributes(self): |
| 1244 | + a = self.create_array(shape=10, chunks=10, dtype='i8') |
| 1245 | + a.attrs['foo'] = 'bar' |
| 1246 | + attrs = json.loads(ensure_str(a.store[a.attrs.key])) |
| 1247 | + assert 'foo' in attrs and attrs['foo'] == 'bar' |
| 1248 | + a.attrs['bar'] = 'foo' |
| 1249 | + attrs = json.loads(ensure_str(a.store[a.attrs.key])) |
| 1250 | + assert 'foo' in attrs and attrs['foo'] == 'bar' |
| 1251 | + assert 'bar' in attrs and attrs['bar'] == 'foo' |
| 1252 | + |
1218 | 1253 |
|
1219 | 1254 | class TestArrayWithPath(TestArray):
|
1220 | 1255 |
|
|
0 commit comments