Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_check_is_iterable():
assert check_is_iterable([1,2,3]) is True
assert check_is_iterable(1) is False
def test_check_is_iterable():
assert check_is_iterable([1,2,3]) is True
assert check_is_iterable(1) is False
# Get list of dumpable dtypes
dumpable_dtypes = []
for lst in [[bool, complex, bytes, float], string_types, integer_types]:
dumpable_dtypes.extend(lst)
# Firstly, check if item is a numpy array. If so, just dump it.
if check_is_ndarray_like(py_obj):
create_hkl_dataset(py_obj, h_group, call_id, **kwargs)
# Next, check if item is a dict
elif isinstance(py_obj, dict):
create_hkl_dataset(py_obj, h_group, call_id, **kwargs)
# If not, check if item is iterable
elif check_is_iterable(py_obj):
item_type = check_iterable_item_type(py_obj)
# item_type == False implies multiple types. Create a dataset
if item_type is False:
h_subgroup = create_hkl_group(py_obj, h_group, call_id)
for ii, py_subobj in enumerate(py_obj):
_dump(py_subobj, h_subgroup, call_id=ii, **kwargs)
# otherwise, subitems have same type. Check if subtype is an iterable
# (e.g. list of lists), or not (e.g. list of ints, which should be treated
# as a single dataset).
else:
if item_type in dumpable_dtypes:
create_hkl_dataset(py_obj, h_group, call_id, **kwargs)
else:
h_subgroup = create_hkl_group(py_obj, h_group, call_id)