21
21
from zarr .codecs import Zlib
22
22
23
23
24
+ # something bcolz-like
25
+ class MockBcolzArray (object ):
26
+
27
+ def __init__ (self , data , chunklen ):
28
+ self .data = data
29
+ self .chunklen = chunklen
30
+
31
+ def __getattr__ (self , item ):
32
+ return getattr (self .data , item )
33
+
34
+ def __getitem__ (self , item ):
35
+ return self .data [item ]
36
+
37
+
38
+ # something h5py-like
39
+ class MockH5pyDataset (object ):
40
+
41
+ def __init__ (self , data , chunks ):
42
+ self .data = data
43
+ self .chunks = chunks
44
+
45
+ def __getattr__ (self , item ):
46
+ return getattr (self .data , item )
47
+
48
+ def __getitem__ (self , item ):
49
+ return self .data [item ]
50
+
51
+
24
52
def test_array ():
25
53
26
54
# with numpy array
@@ -44,25 +72,23 @@ def test_array():
44
72
eq (z .dtype , z2 .dtype )
45
73
assert_array_equal (z [:], z2 [:])
46
74
47
- # with something bcolz-like
48
- class MockBcolzArray (object ):
49
-
50
- def __init__ (self , data , chunklen ):
51
- self .data = data
52
- self .chunklen = chunklen
53
-
54
- def __getattr__ (self , item ):
55
- return getattr (self .data , item )
56
-
57
- def __getitem__ (self , item ):
58
- return self .data [item ]
59
-
60
75
b = np .arange (1000 ).reshape (100 , 10 )
61
76
c = MockBcolzArray (b , 10 )
62
77
z3 = array (c )
63
78
eq (c .shape , z3 .shape )
64
79
eq ((10 , 10 ), z3 .chunks )
65
80
81
+ b = np .arange (1000 ).reshape (100 , 10 )
82
+ c = MockH5pyDataset (b , chunks = (10 , 2 ))
83
+ z4 = array (c )
84
+ eq (c .shape , z4 .shape )
85
+ eq ((10 , 2 ), z4 .chunks )
86
+
87
+ c = MockH5pyDataset (b , chunks = None )
88
+ z5 = array (c )
89
+ eq (c .shape , z5 .shape )
90
+ assert_is_instance (z5 .chunks , tuple )
91
+
66
92
67
93
def test_empty ():
68
94
z = empty (100 , chunks = 10 )
@@ -174,6 +200,7 @@ def test_open_array():
174
200
175
201
176
202
def test_empty_like ():
203
+
177
204
# zarr array
178
205
z = empty (100 , chunks = 10 , dtype = 'f4' , compressor = Zlib (5 ),
179
206
order = 'F' )
@@ -184,18 +211,35 @@ def test_empty_like():
184
211
eq (z .compressor .get_config (), z2 .compressor .get_config ())
185
212
eq (z .fill_value , z2 .fill_value )
186
213
eq (z .order , z2 .order )
214
+
187
215
# numpy array
188
216
a = np .empty (100 , dtype = 'f4' )
189
217
z3 = empty_like (a )
190
218
eq (a .shape , z3 .shape )
191
219
eq ((100 ,), z3 .chunks )
192
220
eq (a .dtype , z3 .dtype )
193
221
assert_is_none (z3 .fill_value )
222
+
194
223
# something slightly silly
195
224
a = [0 ] * 100
196
225
z3 = empty_like (a , shape = 200 )
197
226
eq ((200 ,), z3 .shape )
198
227
228
+ # other array-likes
229
+ b = np .arange (1000 ).reshape (100 , 10 )
230
+ c = MockBcolzArray (b , 10 )
231
+ z = empty_like (c )
232
+ eq (b .shape , z .shape )
233
+ eq ((10 , 10 ), z .chunks )
234
+ c = MockH5pyDataset (b , chunks = (10 , 2 ))
235
+ z = empty_like (c )
236
+ eq (b .shape , z .shape )
237
+ eq ((10 , 2 ), z .chunks )
238
+ c = MockH5pyDataset (b , chunks = None )
239
+ z = empty_like (c )
240
+ eq (b .shape , z .shape )
241
+ assert_is_instance (z .chunks , tuple )
242
+
199
243
200
244
def test_zeros_like ():
201
245
# zarr array
0 commit comments