@@ -3738,6 +3738,7 @@ class ShardsConfigParam(TypedDict):
37383738async def from_array (
37393739 data : Array | npt .ArrayLike ,
37403740 store : str | StoreLike ,
3741+ write_data : bool = True ,
37413742 * ,
37423743 name : str | None = None ,
37433744 chunks : Literal ["auto" , "keep" ] | ChunkCoords = "keep" ,
@@ -3766,6 +3767,10 @@ async def from_array(
37663767 name : str or None, optional
37673768 The name of the array within the store. If ``name`` is ``None``, the array will be located
37683769 at the root of the store.
3770+ write_data : bool, default True
3771+ Whether to copy the data from the input array to the new array.
3772+ If ``write_data`` is ``False``, the new array will be created with the same metadata as the
3773+ input array, but without any data.
37693774 chunks : ChunkCoords or "auto" or "keep", optional
37703775 Chunk shape of the array.
37713776 If not specified, defaults to the chunk shape of the data array.
@@ -3893,6 +3898,9 @@ async def from_array(
38933898 compressors = "auto"
38943899 if serializer == "keep" :
38953900 serializer = "auto"
3901+ if not hasattr (data , "dtype" ) or not hasattr (data , "shape" ):
3902+ data = np .array (data )
3903+ print (data .shape )
38963904 new_array = await create_array (
38973905 store ,
38983906 name = name ,
@@ -3913,29 +3921,30 @@ async def from_array(
39133921 overwrite = overwrite ,
39143922 config = config ,
39153923 )
3916- if isinstance (data , Array ):
3924+ if write_data :
3925+ if isinstance (data , Array ):
39173926
3918- async def _copy_region (chunk_coords : ChunkCoords | slice , _data : Array ) -> None :
3919- arr = await _data ._async_array .getitem (chunk_coords )
3920- await new_array .setitem (chunk_coords , arr )
3927+ async def _copy_region (chunk_coords : ChunkCoords | slice , _data : Array ) -> None :
3928+ arr = await _data ._async_array .getitem (chunk_coords )
3929+ await new_array .setitem (chunk_coords , arr )
39213930
3922- # Stream data from the source array to the new array
3923- await concurrent_map (
3924- [(region , data ) for region in new_array ._iter_chunk_regions ()],
3925- _copy_region ,
3926- zarr .core .config .config .get ("async.concurrency" ),
3927- )
3928- else :
3931+ # Stream data from the source array to the new array
3932+ await concurrent_map (
3933+ [(region , data ) for region in new_array ._iter_chunk_regions ()],
3934+ _copy_region ,
3935+ zarr .core .config .config .get ("async.concurrency" ),
3936+ )
3937+ else :
39293938
3930- async def _copy_region (chunk_coords : ChunkCoords | slice , _data : npt .ArrayLike ) -> None :
3931- await new_array .setitem (chunk_coords , _data [chunk_coords ])
3939+ async def _copy_region (chunk_coords : ChunkCoords | slice , _data : npt .ArrayLike ) -> None :
3940+ await new_array .setitem (chunk_coords , _data [chunk_coords ])
39323941
3933- # Stream data from the source array to the new array
3934- await concurrent_map (
3935- [(region , data ) for region in new_array ._iter_chunk_regions ()],
3936- _copy_region ,
3937- zarr .core .config .config .get ("async.concurrency" ),
3938- )
3942+ # Stream data from the source array to the new array
3943+ await concurrent_map (
3944+ [(region , data ) for region in new_array ._iter_chunk_regions ()],
3945+ _copy_region ,
3946+ zarr .core .config .config .get ("async.concurrency" ),
3947+ )
39393948 return new_array
39403949
39413950
0 commit comments