From 06d82a73b8c7de5da22343492e5f56161799a283 Mon Sep 17 00:00:00 2001 From: 1313e Date: Tue, 5 Jan 2021 14:46:28 +1100 Subject: [PATCH] Solely iterable datasets will now be able to use compression. All other keywords are ignored, as they are either used by hickle itself or serve no purpose with hickle. This fixes telegraphic/hickle#140. --- hickle/hickle.py | 6 +++++- hickle/loaders/load_builtins.py | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hickle/hickle.py b/hickle/hickle.py index e9aeee8b..8dee851d 100644 --- a/hickle/hickle.py +++ b/hickle/hickle.py @@ -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) @@ -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 diff --git a/hickle/loaders/load_builtins.py b/hickle/loaders/load_builtins.py index a4e438ad..a00c01a4 100644 --- a/hickle/loaders/load_builtins.py +++ b/hickle/loaders/load_builtins.py @@ -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')