1010import numpy as np
1111import pytest
1212from numcodecs import Zstd
13+ from numpy import dtype
14+ from numpy .ma .testutils import assert_array_equal
1315
1416import zarr .api .asynchronous
1517from zarr import Array , AsyncArray , Group
@@ -892,21 +894,30 @@ async def test_scalar_array() -> None:
892894
893895
894896async def test_creation_from_other_zarr (tmpdir ):
895- src = zarr .zeros (
896- (2000 , 20000 ), chunks = (1000 , 1000 ), dtype = "uint8" , store = LocalStore (str (tmpdir ))
897- )
898- src [:] = 1
899- for _i in range (10 ):
900- start_time = time .time ()
901- c = zarr .array (src , store = MemoryStore ())
902- end_time = time .time ()
903- print (f"Time fast: { end_time - start_time } seconds" )
904-
905- start_time = time .time ()
906- b = zarr .zeros (src .shape , chunks = src .chunks , store = MemoryStore ())
907- b [:] = src [:]
908- end_time = time .time ()
909- print (f"Time slow: { end_time - start_time } seconds" )
910-
911- assert b [123 , 123 ] == 1
912- assert c [123 , 123 ] == 1
897+ src_fill_value = 2
898+ src_dtype = np .dtype ("uint8" )
899+ src_attributes = {}
900+ src_chunks = (2 , 2 )
901+
902+ src = zarr .create ((10 , 10 ), chunks = src_chunks , dtype = src_dtype , store = LocalStore (str (tmpdir )), fill_value = src_fill_value , attributes = src_attributes )
903+ src [:] = np .arange (100 ).reshape ((10 ,10 ))
904+
905+ result = zarr .array (src , store = MemoryStore ())
906+ assert_array_equal (result [:], src [:])
907+ assert result .fill_value == src_fill_value
908+ assert result .dtype == src_dtype
909+ assert result .attrs .asdict () == src_attributes
910+ assert result .chunks == src_chunks
911+
912+ new_fill_value = 3
913+ new_dtype = np .dtype ("uint16" )
914+ new_attributes = {"foo" :"bar" }
915+ new_chunks = (5 , 10 )
916+
917+ result2 = zarr .array (src , store = MemoryStore (), chunks = new_chunks , dtype = new_dtype , fill_value = new_fill_value , attributes = new_attributes )
918+
919+ assert_array_equal (result2 [:], src [:])
920+ assert result2 .fill_value == new_fill_value
921+ assert result2 .dtype == new_dtype
922+ assert result2 .attrs == new_attributes
923+ assert result2 .chunks == new_chunks
0 commit comments