Skip to content

Commit 678eb23

Browse files
committed
add dump docstrings
1 parent eaff290 commit 678eb23

1 file changed

Lines changed: 147 additions & 2 deletions

File tree

asdf/_dump.py

Lines changed: 147 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,43 @@ def dump(
1818
pad_blocks=False,
1919
custom_schema=None,
2020
):
21+
"""
22+
Write a tree to an ASDF file.
23+
24+
Parameters
25+
----------
26+
tree : object
27+
The tree to dump.
28+
29+
fp : str or file-like object
30+
A file-like object to write the ASDF data to.
31+
32+
version : str, optional
33+
Version of the ASDF Standard to use. If not specified, the default
34+
version will be used.
35+
36+
extensions : object, optional
37+
Additional extensions to use when reading and writing the file.
38+
May be an `asdf.extension.Extension` or a `list` of extensions.
39+
40+
all_array_storage : string, optional
41+
If provided, override the array storage type of all blocks.
42+
43+
all_array_compression : string, optional
44+
If provided, override the array compression type of all blocks.
45+
46+
compression_kwargs : dict, optional
47+
If provided, override the compression parameters of all blocks.
48+
49+
pad_blocks : bool, optional
50+
If provided, pad all blocks to the nearest multiple of the block size.
51+
52+
custom_schema : str, optional
53+
Path to a custom schema file that will be used for a secondary
54+
validation pass. This can be used to ensure that particular ASDF
55+
files follow custom conventions beyond those enforced by the
56+
standard.
57+
"""
2158
AsdfFile(tree, custom_schema=custom_schema, extensions=extensions).write_to(
2259
fp,
2360
version=version,
@@ -39,6 +76,45 @@ def dumps(
3976
pad_blocks=False,
4077
custom_schema=None,
4178
):
79+
"""
80+
Write tree to a string.
81+
82+
Parameters
83+
----------
84+
tree : object
85+
The tree to dump.
86+
87+
version : str, optional
88+
Version of the ASDF Standard to use. If not specified, the default
89+
version will be used.
90+
91+
extensions : object, optional
92+
Additional extensions to use when reading and writing the file.
93+
May be an `asdf.extension.Extension` or a `list` of extensions.
94+
95+
all_array_storage : string, optional
96+
If provided, override the array storage type of all blocks.
97+
98+
all_array_compression : string, optional
99+
If provided, override the array compression type of all blocks.
100+
101+
compression_kwargs : dict, optional
102+
If provided, override the compression parameters of all blocks.
103+
104+
pad_blocks : bool, optional
105+
If provided, pad all blocks to the nearest multiple of the block size.
106+
107+
custom_schema : str, optional
108+
Path to a custom schema file that will be used for a secondary
109+
validation pass. This can be used to ensure that particular ASDF
110+
files follow custom conventions beyond those enforced by the
111+
standard.
112+
113+
Returns
114+
-------
115+
str
116+
The ASDF data as a string.
117+
"""
42118
buff = BytesIO()
43119
dump(
44120
tree,
@@ -55,6 +131,38 @@ def dumps(
55131

56132

57133
def load(fp, *, uri=None, validate_checksums=False, extensions=None, custom_schema=None):
134+
"""
135+
Load the ASDF tree from a file-like object.
136+
137+
Parameters
138+
----------
139+
fp : str or file-like object
140+
A file-like object to read the ASDF data from.
141+
142+
uri : str, optional
143+
The URI for this ASDF file. Used to resolve relative
144+
references against. If not provided, will be
145+
automatically determined from the associated file object,
146+
if possible and if created from `asdf.open`.
147+
148+
validate_checksums : bool, optional
149+
If `True`, validate the blocks against their checksums.
150+
151+
extensions : object, optional
152+
Additional extensions to use when reading and writing the file.
153+
May be an `asdf.extension.Extension` or a `list` of extensions.
154+
155+
custom_schema : str, optional
156+
Path to a custom schema file that will be used for a secondary
157+
validation pass. This can be used to ensure that particular ASDF
158+
files follow custom conventions beyond those enforced by the
159+
standard.
160+
161+
Returns
162+
-------
163+
object:
164+
The ASDF tree.
165+
"""
58166
with open_asdf(
59167
fp,
60168
lazy_load=False,
@@ -68,7 +176,44 @@ def load(fp, *, uri=None, validate_checksums=False, extensions=None, custom_sche
68176
return af.tree
69177

70178

71-
def loads(fp, *, uri=None, validate_checksums=False, extensions=None, custom_schema=None):
179+
def loads(asdf_string, *, uri=None, validate_checksums=False, extensions=None, custom_schema=None):
180+
"""
181+
Load the ASDF tree from a string..
182+
183+
Parameters
184+
----------
185+
asdf_string : str
186+
A string containing ASDF data.
187+
188+
uri : str, optional
189+
The URI for this ASDF file. Used to resolve relative
190+
references against. If not provided, will be
191+
automatically determined from the associated file object,
192+
if possible and if created from `asdf.open`.
193+
194+
validate_checksums : bool, optional
195+
If `True`, validate the blocks against their checksums.
196+
197+
extensions : object, optional
198+
Additional extensions to use when reading and writing the file.
199+
May be an `asdf.extension.Extension` or a `list` of extensions.
200+
201+
custom_schema : str, optional
202+
Path to a custom schema file that will be used for a secondary
203+
validation pass. This can be used to ensure that particular ASDF
204+
files follow custom conventions beyond those enforced by the
205+
standard.
206+
207+
Returns
208+
-------
209+
object:
210+
The ASDF tree.
211+
"""
212+
72213
return load(
73-
BytesIO(fp), uri=uri, validate_checksums=validate_checksums, extensions=extensions, custom_schema=custom_schema
214+
BytesIO(asdf_string),
215+
uri=uri,
216+
validate_checksums=validate_checksums,
217+
extensions=extensions,
218+
custom_schema=custom_schema,
74219
)

0 commit comments

Comments
 (0)