@@ -837,7 +837,7 @@ async def open(
837837 Examples
838838 --------
839839 >>> import zarr
840- >>> store = zarr.storage.MemoryStore(mode='w' )
840+ >>> store = zarr.storage.MemoryStore()
841841 >>> async_arr = await AsyncArray.open(store) # doctest: +ELLIPSIS
842842 <AsyncArray memory://... shape=(100, 100) dtype=int32>
843843 """
@@ -1269,7 +1269,7 @@ async def getitem(
12691269 Examples
12701270 --------
12711271 >>> import zarr
1272- >>> store = zarr.storage.MemoryStore(mode='w' )
1272+ >>> store = zarr.storage.MemoryStore()
12731273 >>> async_arr = await zarr.api.asynchronous.create_array(
12741274 ... store=store,
12751275 ... shape=(100,100),
@@ -3760,22 +3760,24 @@ async def from_array(
37603760
37613761 Parameters
37623762 ----------
3763- data : Array
3763+ data : Array | array-like
37643764 The array to copy.
37653765 store : str or Store
37663766 Store or path to directory in file system or name of zip file for the new array.
3767- name : str or None, optional
3768- The name of the array within the store. If ``name`` is ``None``, the array will be located
3769- at the root of the store.
37703767 write_data : bool, default True
37713768 Whether to copy the data from the input array to the new array.
37723769 If ``write_data`` is ``False``, the new array will be created with the same metadata as the
37733770 input array, but without any data.
3771+ name : str or None, optional
3772+ The name of the array within the store. If ``name`` is ``None``, the array will be located
3773+ at the root of the store.
37743774 chunks : ChunkCoords or "auto" or "keep", optional
37753775 Chunk shape of the array.
3776- If not specified, defaults to the chunk shape of the data array.
3777- - "auto": Automatically determine the chunk shape based on the array's shape and dtype.
3778- - "keep": Retain the chunk shape of the input array.
3776+ Following values are supported:
3777+ - "auto": Automatically determine the chunk shape based on the array's shape and dtype.
3778+ - "keep": Retain the chunk shape of the data array if it is a zarr Array.
3779+ - ChunkCoords: A tuple of integers representing the chunk shape.
3780+ If not specified, defaults to "keep" if data is a zarr Array, otherwise "auto".
37793781 shards : ChunkCoords, optional
37803782 Shard shape of the array. The default value of ``None`` results in no sharding at all.
37813783 filters : Iterable[Codec] or "auto" or "keep", optional
@@ -3789,9 +3791,11 @@ async def from_array(
37893791 For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the
37903792 the order if your filters is consistent with the behavior of each filter.
37913793
3792- If no ``filters`` are provided, defaults to the filters of the data array.
3794+ Following values are supported:
3795+ - Iterable[Codec]: List of filters to apply to the array.
37933796 - "auto": Automatically determine the filters based on the array's dtype.
3794- - "keep": Retain the filters of the input array.
3797+ - "keep": Retain the filters of the data array if it is a zarr Array.
3798+ If no ``filters`` are provided, defaults to "keep" if data is a zarr Array, otherwise "auto".
37953799 compressors : Iterable[Codec] or "auto" or "keep", optional
37963800 List of compressors to apply to the array. Compressors are applied in order, and after any
37973801 filters are applied (if any are specified) and the data is serialized into bytes.
@@ -3802,16 +3806,21 @@ async def from_array(
38023806 For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may
38033807 be provided for Zarr format 2.
38043808
3805- If no ``compressors`` are provided, defaults to the compressors of the data array.
3809+ Following values are supported:
3810+ - Iterable[Codec]: List of compressors to apply to the array.
38063811 - "auto": Automatically determine the compressors based on the array's dtype.
3807- - "keep": Retain the compressors of the input array.
3812+ - "keep": Retain the compressors of the input array if it is a zarr Array.
3813+ If no ``compressors`` are provided, defaults to "keep" if data is a zarr Array, otherwise "auto".
38083814 serializer : dict[str, JSON] | ArrayBytesCodec or "auto" or "keep", optional
38093815 Array-to-bytes codec to use for encoding the array data.
38103816 Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion.
38113817
3812- If no ``serializer`` is provided, defaults to the serializer of the input array.
3813- - "auto": Automatically determine the serializer based on the array's dtype.
3814- - "keep": Retain the serializer of the input array.
3818+ Following values are supported:
3819+ - dict[str, JSON]: A dict representation of an ``ArrayBytesCodec``.
3820+ - ArrayBytesCodec: An instance of ``ArrayBytesCodec``.
3821+ - "auto": a default serializer will be used. These defaults can be changed by modifying the value of
3822+ ``array.v3_default_serializer`` in :mod:`zarr.core.config`.
3823+ - "keep": Retain the serializer of the input array if it is a zarr Array.
38153824 fill_value : Any, optional
38163825 Fill value for the array.
38173826 If not specified, defaults to the fill value of the data array.
@@ -3853,9 +3862,47 @@ async def from_array(
38533862
38543863 Examples
38553864 --------
3856- #TODO
3865+ Create an array from an existing Array:
3866+ >>> import zarr
3867+ >>> store = zarr.storage.MemoryStore()
3868+ >>> store2 = zarr.storage.LocalStore('example.zarr')
3869+ >>> arr = zarr.create_array(
3870+ >>> store=store,
3871+ >>> shape=(100,100),
3872+ >>> chunks=(10,10),
3873+ >>> dtype='int32',
3874+ >>> fill_value=0)
3875+ >>> arr2 = await zarr.api.asynchronous.from_array(arr, store=store2)
3876+ <AsyncArray file://example.zarr shape=(100, 100) dtype=int32>
3877+
3878+ Create an array from an existing NumPy array:
3879+ >>> arr3 = await zarr.api.asynchronous.from_array(
3880+ >>> np.arange(10000, dtype='i4').reshape(100, 100),
3881+ >>> store=zarr.storage.MemoryStore(),
3882+ >>> )
3883+ <AsyncArray memory://123286956732800 shape=(100, 100) dtype=int32>
3884+
3885+ Create an array from any array-like object:
3886+ >>> arr4 = await zarr.api.asynchronous.from_array(
3887+ >>> [[1, 2], [3, 4]],
3888+ >>> store=zarr.storage.MemoryStore(),
3889+ >>> )
3890+ <AsyncArray memory://123286959761024 shape=(2, 2) dtype=int64>
3891+ >>> await arr4.getitem(...)
3892+ array([[1, 2],
3893+ [3, 4]])
3894+
3895+ Create an array from an existing Array without copying the data:
3896+ >>> arr5 = await zarr.api.asynchronous.from_array(
3897+ >>> Array(arr4),
3898+ >>> store=zarr.storage.MemoryStore(),
3899+ >>> write_data=False,
3900+ >>> )
3901+ <AsyncArray memory://140678602965568 shape=(2, 2) dtype=int64>
3902+ >>> await arr5.getitem(...)
3903+ array([[0, 0],
3904+ [0, 0]])
38573905 """
3858-
38593906 if isinstance (data , Array ):
38603907 if chunks == "keep" :
38613908 chunks = data .chunks
@@ -3900,7 +3947,6 @@ async def from_array(
39003947 serializer = "auto"
39013948 if not hasattr (data , "dtype" ) or not hasattr (data , "shape" ):
39023949 data = np .array (data )
3903- print (data .shape )
39043950 new_array = await create_array (
39053951 store ,
39063952 name = name ,
@@ -4064,7 +4110,7 @@ async def create_array(
40644110 Examples
40654111 --------
40664112 >>> import zarr
4067- >>> store = zarr.storage.MemoryStore(mode='w' )
4113+ >>> store = zarr.storage.MemoryStore()
40684114 >>> async_arr = await zarr.api.asynchronous.create_array(
40694115 >>> store=store,
40704116 >>> shape=(100,100),
0 commit comments