99import numpy .typing as npt
1010from typing_extensions import deprecated
1111
12- from zarr .core .array import Array , AsyncArray , create_array , get_array_metadata
12+ from zarr .core .array import Array , AsyncArray , create_array , from_array , get_array_metadata
1313from zarr .core .array_spec import ArrayConfig , ArrayConfigLike , ArrayConfigParams
1414from zarr .core .buffer import NDArrayLike
1515from zarr .core .common import (
3838 from collections .abc import Iterable
3939
4040 from zarr .abc .codec import Codec
41+ from zarr .core .buffer import NDArrayLikeOrScalar
4142 from zarr .core .chunk_key_encodings import ChunkKeyEncoding
4243 from zarr .storage import StoreLike
4344
5657 "create_hierarchy" ,
5758 "empty" ,
5859 "empty_like" ,
60+ "from_array" ,
5961 "full" ,
6062 "full_like" ,
6163 "group" ,
@@ -238,7 +240,7 @@ async def load(
238240 path : str | None = None ,
239241 zarr_format : ZarrFormat | None = None ,
240242 zarr_version : ZarrFormat | None = None ,
241- ) -> NDArrayLike | dict [str , NDArrayLike ]:
243+ ) -> NDArrayLikeOrScalar | dict [str , NDArrayLikeOrScalar ]:
242244 """Load data from an array or group into memory.
243245
244246 Parameters
@@ -533,7 +535,7 @@ async def tree(grp: AsyncGroup, expand: bool | None = None, level: int | None =
533535
534536
535537async def array (
536- data : npt .ArrayLike , ** kwargs : Any
538+ data : npt .ArrayLike | Array , ** kwargs : Any
537539) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
538540 """Create an array filled with `data`.
539541
@@ -550,13 +552,16 @@ async def array(
550552 The new array.
551553 """
552554
555+ if isinstance (data , Array ):
556+ return await from_array (data = data , ** kwargs )
557+
553558 # ensure data is array-like
554559 if not hasattr (data , "shape" ) or not hasattr (data , "dtype" ):
555560 data = np .asanyarray (data )
556561
557562 # setup dtype
558563 kw_dtype = kwargs .get ("dtype" )
559- if kw_dtype is None :
564+ if kw_dtype is None and hasattr ( data , "dtype" ) :
560565 kwargs ["dtype" ] = data .dtype
561566 else :
562567 kwargs ["dtype" ] = kw_dtype
0 commit comments