Skip to content

Commit 29074fd

Browse files
committed
format docstring examples
1 parent e3d691d commit 29074fd

File tree

2 files changed

+85
-77
lines changed

2 files changed

+85
-77
lines changed

src/zarr/api/synchronous.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,45 +1029,49 @@ def from_array(
10291029
10301030
Examples
10311031
--------
1032-
Create an array from an existing Array:
1033-
>>> import zarr
1034-
>>> store = zarr.storage.MemoryStore()
1035-
>>> store2 = zarr.storage.LocalStore('example.zarr')
1036-
>>> arr = zarr.create_array(
1037-
>>> store=store,
1038-
>>> shape=(100,100),
1039-
>>> chunks=(10,10),
1040-
>>> dtype='int32',
1041-
>>> fill_value=0)
1042-
>>> arr2 = zarr.from_array(arr, store=store2)
1043-
<Array file://example.zarr shape=(100, 100) dtype=int32>
1044-
1045-
Create an array from an existing NumPy array:
1046-
>>> import numpy as np
1047-
>>> arr3 = zarr.from_array(
1048-
>>> np.arange(10000, dtype='i4').reshape(100, 100),
1049-
>>> store=zarr.storage.MemoryStore(),
1050-
>>> )
1051-
<Array memory://125477403529984 shape=(100, 100) dtype=int32>
1052-
1053-
Create an array from any array-like object:
1054-
>>> arr4 = zarr.from_array(
1055-
>>> [[1, 2], [3, 4]],
1056-
>>> store= zarr.storage.MemoryStore(),
1057-
>>> )
1058-
<Array memory://125477392154368 shape=(2, 2) dtype=int64>
1059-
>>> arr4[...]
1060-
array([[1, 2],[3, 4]])
1061-
1062-
Create an array from an existing Array without copying the data:
1063-
>>> arr5 = zarr.from_array(
1064-
>>> arr4,
1065-
>>> store=zarr.storage.MemoryStore(),
1066-
>>> write_data=False,
1067-
>>> )
1068-
<Array memory://140678602965568 shape=(2, 2) dtype=int64>
1069-
>>> arr5[...]
1070-
array([[0, 0],[0, 0]])
1032+
Create an array from an existing Array::
1033+
1034+
>>> import zarr
1035+
>>> store = zarr.storage.MemoryStore()
1036+
>>> store2 = zarr.storage.LocalStore('example.zarr')
1037+
>>> arr = zarr.create_array(
1038+
>>> store=store,
1039+
>>> shape=(100,100),
1040+
>>> chunks=(10,10),
1041+
>>> dtype='int32',
1042+
>>> fill_value=0)
1043+
>>> arr2 = zarr.from_array(arr, store=store2)
1044+
<Array file://example.zarr shape=(100, 100) dtype=int32>
1045+
1046+
Create an array from an existing NumPy array::
1047+
1048+
>>> import numpy as np
1049+
>>> arr3 = zarr.from_array(
1050+
>>> np.arange(10000, dtype='i4').reshape(100, 100),
1051+
>>> store=zarr.storage.MemoryStore(),
1052+
>>> )
1053+
<Array memory://125477403529984 shape=(100, 100) dtype=int32>
1054+
1055+
Create an array from any array-like object::
1056+
1057+
>>> arr4 = zarr.from_array(
1058+
>>> [[1, 2], [3, 4]],
1059+
>>> store= zarr.storage.MemoryStore(),
1060+
>>> )
1061+
<Array memory://125477392154368 shape=(2, 2) dtype=int64>
1062+
>>> arr4[...]
1063+
array([[1, 2],[3, 4]])
1064+
1065+
Create an array from an existing Array without copying the data::
1066+
1067+
>>> arr5 = zarr.from_array(
1068+
>>> arr4,
1069+
>>> store=zarr.storage.MemoryStore(),
1070+
>>> write_data=False,
1071+
>>> )
1072+
<Array memory://140678602965568 shape=(2, 2) dtype=int64>
1073+
>>> arr5[...]
1074+
array([[0, 0],[0, 0]])
10711075
"""
10721076
return Array(
10731077
sync(

src/zarr/core/array.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,44 +3878,48 @@ async def from_array(
38783878
38793879
Examples
38803880
--------
3881-
Create an array from an existing Array:
3882-
>>> import zarr
3883-
>>> store = zarr.storage.MemoryStore()
3884-
>>> store2 = zarr.storage.LocalStore('example.zarr')
3885-
>>> arr = zarr.create_array(
3886-
>>> store=store,
3887-
>>> shape=(100,100),
3888-
>>> chunks=(10,10),
3889-
>>> dtype='int32',
3890-
>>> fill_value=0)
3891-
>>> arr2 = await zarr.api.asynchronous.from_array(arr, store=store2)
3892-
<AsyncArray file://example.zarr shape=(100, 100) dtype=int32>
3893-
3894-
Create an array from an existing NumPy array:
3895-
>>> arr3 = await zarr.api.asynchronous.from_array(
3896-
>>> np.arange(10000, dtype='i4').reshape(100, 100),
3897-
>>> store=zarr.storage.MemoryStore(),
3898-
>>> )
3899-
<AsyncArray memory://123286956732800 shape=(100, 100) dtype=int32>
3900-
3901-
Create an array from any array-like object:
3902-
>>> arr4 = await zarr.api.asynchronous.from_array(
3903-
>>> [[1, 2], [3, 4]],
3904-
>>> store=zarr.storage.MemoryStore(),
3905-
>>> )
3906-
<AsyncArray memory://123286959761024 shape=(2, 2) dtype=int64>
3907-
>>> await arr4.getitem(...)
3908-
array([[1, 2],[3, 4]])
3909-
3910-
Create an array from an existing Array without copying the data:
3911-
>>> arr5 = await zarr.api.asynchronous.from_array(
3912-
>>> Array(arr4),
3913-
>>> store=zarr.storage.MemoryStore(),
3914-
>>> write_data=False,
3915-
>>> )
3916-
<AsyncArray memory://140678602965568 shape=(2, 2) dtype=int64>
3917-
>>> await arr5.getitem(...)
3918-
array([[0, 0],[0, 0]])
3881+
Create an array from an existing Array::
3882+
3883+
>>> import zarr
3884+
>>> store = zarr.storage.MemoryStore()
3885+
>>> store2 = zarr.storage.LocalStore('example.zarr')
3886+
>>> arr = zarr.create_array(
3887+
>>> store=store,
3888+
>>> shape=(100,100),
3889+
>>> chunks=(10,10),
3890+
>>> dtype='int32',
3891+
>>> fill_value=0)
3892+
>>> arr2 = await zarr.api.asynchronous.from_array(arr, store=store2)
3893+
<AsyncArray file://example.zarr shape=(100, 100) dtype=int32>
3894+
3895+
Create an array from an existing NumPy array::
3896+
3897+
>>> arr3 = await zarr.api.asynchronous.from_array(
3898+
>>> np.arange(10000, dtype='i4').reshape(100, 100),
3899+
>>> store=zarr.storage.MemoryStore(),
3900+
>>> )
3901+
<AsyncArray memory://123286956732800 shape=(100, 100) dtype=int32>
3902+
3903+
Create an array from any array-like object::
3904+
3905+
>>> arr4 = await zarr.api.asynchronous.from_array(
3906+
>>> [[1, 2], [3, 4]],
3907+
>>> store=zarr.storage.MemoryStore(),
3908+
>>> )
3909+
<AsyncArray memory://123286959761024 shape=(2, 2) dtype=int64>
3910+
>>> await arr4.getitem(...)
3911+
array([[1, 2],[3, 4]])
3912+
3913+
Create an array from an existing Array without copying the data::
3914+
3915+
>>> arr5 = await zarr.api.asynchronous.from_array(
3916+
>>> Array(arr4),
3917+
>>> store=zarr.storage.MemoryStore(),
3918+
>>> write_data=False,
3919+
>>> )
3920+
<AsyncArray memory://140678602965568 shape=(2, 2) dtype=int64>
3921+
>>> await arr5.getitem(...)
3922+
array([[0, 0],[0, 0]])
39193923
"""
39203924
if isinstance(data, Array):
39213925
if chunks == "keep":

0 commit comments

Comments
 (0)