Skip to content

Commit

Permalink
remove kwargs and document keyword argument for write_to and update
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Jul 18, 2023
1 parent 14ab9f0 commit c4adc36
Showing 1 changed file with 56 additions and 30 deletions.
86 changes: 56 additions & 30 deletions asdf/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,15 @@ def _post_write(self, fd):
if len(self._tree):
self._run_hook("post_write")

def update(self, **kwargs):
def update(
self,
all_array_storage=NotSet,
all_array_compression=NotSet,
compression_kwargs=NotSet,
pad_blocks=False,
include_block_index=True,
version=None,
):
"""
Update the file on disk in place.
Expand Down Expand Up @@ -1032,6 +1040,10 @@ def update(self, **kwargs):
- ``input``: Use the same compression as in the file read.
If there is no prior file, acts as None
compression_kwargs : dict, optional
If provided, set this as the compression keyword arguments
for all binary blocks in the file.
pad_blocks : float or bool, optional
Add extra space between blocks to allow for updating of
the file. If `False` (default), add no padding (always
Expand All @@ -1049,17 +1061,13 @@ def update(self, **kwargs):
writing.
"""

pad_blocks = kwargs.pop("pad_blocks", False)
include_block_index = kwargs.pop("include_block_index", True)
version = kwargs.pop("version", None)

with config_context() as config:
if "all_array_storage" in kwargs:
config.all_array_storage = kwargs.pop("all_array_storage")
if "all_array_compression" in kwargs:
config.all_array_compression = kwargs.pop("all_array_compression")
if "compression_kwargs" in kwargs:
config.all_array_compression_kwargs = kwargs.pop("compression_kwargs")
if all_array_storage is not NotSet:
config.all_array_storage = all_array_storage
if all_array_compression is not NotSet:
config.all_array_compression = all_array_compression
if compression_kwargs is not NotSet:
config.all_array_compression_kwargs = compression_kwargs

fd = self._fd

Expand Down Expand Up @@ -1142,7 +1150,12 @@ def update(self, **kwargs):
def write_to(
self,
fd,
**kwargs,
all_array_storage=NotSet,
all_array_compression=NotSet,
compression_kwargs=NotSet,
pad_blocks=False,
include_block_index=True,
version=None,
):
"""
Write the ASDF file to the given file-like object.
Expand Down Expand Up @@ -1186,6 +1199,10 @@ def write_to(
- ``input``: Use the same compression as in the file read.
If there is no prior file, acts as None.
compression_kwargs : dict, optional
If provided, set this as the compression keyword arguments
for all binary blocks in the file.
pad_blocks : float or bool, optional
Add extra space between blocks to allow for updating of
the file. If `False` (default), add no padding (always
Expand All @@ -1203,12 +1220,12 @@ def write_to(
writing.
"""
with config_context() as config:
if "all_array_storage" in kwargs:
config.all_array_storage = kwargs["all_array_storage"]
if "all_array_compression" in kwargs:
config.all_array_compression = kwargs["all_array_compression"]
if "compression_kwargs" in kwargs:
config.all_array_compression_kwargs = kwargs["compression_kwargs"]
if all_array_storage is not NotSet:
config.all_array_storage = all_array_storage
if all_array_compression is not NotSet:
config.all_array_compression = all_array_compression
if compression_kwargs is not NotSet:
config.all_array_compression_kwargs = compression_kwargs

used_blocks = self._blocks._find_used_blocks(self.tree, self, remove=False)

Expand Down Expand Up @@ -1253,24 +1270,33 @@ def write_to(
blk = naf._blocks.find_or_create_block(key)
blk._used = True
blk._data_callback = b._data_callback
naf._write_to(fd, **kwargs)
naf._write_to(
fd,
all_array_storage=all_array_storage,
all_array_compression=all_array_compression,
compression_kwargs=compression_kwargs,
pad_blocks=pad_blocks,
include_block_index=include_block_index,
version=version,
)

def _write_to(
self,
fd,
**kwargs,
all_array_storage=NotSet,
all_array_compression=NotSet,
compression_kwargs=NotSet,
pad_blocks=False,
include_block_index=True,
version=None,
):
pad_blocks = kwargs.pop("pad_blocks", False)
include_block_index = kwargs.pop("include_block_index", True)
version = kwargs.pop("version", None)

with config_context() as config:
if "all_array_storage" in kwargs:
config.all_array_storage = kwargs.pop("all_array_storage")
if "all_array_compression" in kwargs:
config.all_array_compression = kwargs.pop("all_array_compression")
if "compression_kwargs" in kwargs:
config.all_array_compression_kwargs = kwargs.pop("compression_kwargs")
if all_array_storage is not NotSet:
config.all_array_storage = all_array_storage
if all_array_compression is not NotSet:
config.all_array_compression = all_array_compression
if compression_kwargs is not NotSet:
config.all_array_compression_kwargs = compression_kwargs

if version is not None:
self.version = version
Expand Down

0 comments on commit c4adc36

Please sign in to comment.