Skip to content

Commit

Permalink
Solely iterable datasets will now be able to use compression.
Browse files Browse the repository at this point in the history
All other keywords are ignored, as they are either used by hickle itself or serve no purpose with hickle.
This fixes #140.
  • Loading branch information
1313e committed Jan 5, 2021
1 parent fe0a879 commit 06d82a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 5 additions & 1 deletion hickle/hickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ def create_hkl_dataset(py_obj, h_group, call_id=None, **kwargs):
# Set the name of this dataset
name = 'data%s' % ("_%i" % (call_id) if call_id is not None else '')

# If this obj is iterable, use compression if given
if hasattr(py_obj, '__iter__') and not isinstance(py_obj, (str, bytes)):
kwargs = {'compression': kwargs.pop('compression', None)}

# Try to create the dataset
try:
h_subgroup = create_dataset(py_obj, h_group, name, **kwargs)
Expand All @@ -310,7 +314,7 @@ def create_hkl_dataset(py_obj, h_group, call_id=None, **kwargs):
pass

# Create the pickled dataset
h_subgroup = create_dataset(py_obj, h_group, name, error, **kwargs)
h_subgroup = create_dataset(py_obj, h_group, name, error)

# Save base type of py_obj
h_subgroup.attrs['base_type'] = base_type
Expand Down
3 changes: 0 additions & 3 deletions hickle/loaders/load_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ def create_scalar_dataset(py_obj, h_group, name, **kwargs):
iterable.
"""

# Make sure 'compression' is not in kwargs
kwargs.pop('compression', None)

# If py_obj is an integer and cannot be stored in 64-bits, convert to str
if isinstance(py_obj, int) and not (-2**63 <= py_obj < 2**64):
py_obj = bytes(str(py_obj), 'ascii')
Expand Down

0 comments on commit 06d82a7

Please sign in to comment.