@@ -169,3 +169,61 @@ def test_unicode_on_disk_persistence(tmp_path):
169169
170170 reopened = blosc2 .open (path )
171171 assert np .array_equal (reopened , arr2 )
172+
173+
174+ @pytest .mark .parametrize (
175+ "constructor" ,
176+ [
177+ "zeros" ,
178+ "ones" ,
179+ "empty" ,
180+ "full" ,
181+ # "full_like", these all call ones/empty/full/zeros anyway
182+ # "zeros_like",
183+ # "ones_like",
184+ # "empty_like",
185+ "eye" ,
186+ ],
187+ )
188+ @pytest .mark .parametrize ("shape" , SHAPES )
189+ def test_constructors (constructor , shape ):
190+ if constructor == "full" :
191+ arr = getattr (blosc2 , constructor )(fill_value = "pepe" , shape = shape , dtype = np .str_ )
192+ nparr = getattr (np , constructor )(fill_value = "pepe" , shape = shape , dtype = np .str_ )
193+ elif constructor == "eye" :
194+ arr = getattr (blosc2 , constructor )(shape [0 ], dtype = np .str_ )
195+ nparr = getattr (np , constructor )(shape [0 ], dtype = np .str_ )
196+ else :
197+ arr = getattr (blosc2 , constructor )(shape = shape , dtype = np .str_ )
198+ nparr = getattr (np , constructor )(shape = shape , dtype = np .str_ )
199+ np .testing .assert_array_equal (arr [()], nparr )
200+
201+
202+ def test_optimised_string_comp ():
203+ N = int (1e5 )
204+ nparr = np .repeat (np .array (["josé" , "pepe" , "francisco" ]), N )
205+ cparams = blosc2 .cparams_dflts
206+ arr1 = blosc2 .asarray (nparr , cparams = cparams )
207+ cratio_subopt = arr1 .cratio
208+ # when not providing cparams, blosc2_ext passes an optimised pipeline for string dtypes
209+ arr1 = blosc2 .asarray (nparr )
210+ assert arr1 .cratio > cratio_subopt
211+
212+
213+ @pytest .mark .parametrize ("shape" , SHAPES )
214+ def test_frombuffer (shape ):
215+ chunks = tuple (max (c // 4 , 1 ) for c in shape )
216+ dtype = np .dtype ("<U8" )
217+ typesize = dtype .itemsize
218+ # Create a buffer
219+ nparr = make_unicode_array (shape , maxlen = 8 )
220+ buffer = bytes (nparr )
221+ # Create a NDArray from a buffer with default blocks
222+ arr = blosc2 .frombuffer (buffer , shape , chunks = chunks , dtype = dtype )
223+ np .testing .assert_array_equal (arr [()], nparr )
224+
225+
226+ def test_fromiter ():
227+ nparr = np .arange (0 , 20 ).astype (np .str_ )
228+ arr = blosc2 .fromiter (range (20 ), shape = (20 ,), dtype = nparr .dtype )
229+ np .testing .assert_array_equal (arr [()], nparr )
0 commit comments