How to use the hickle.helpers.check_is_iterable function in hickle

To help you get started, we’ve selected a few hickle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github telegraphic / hickle / tests / test_hickle_helpers.py View on Github external
def test_check_is_iterable():
    assert check_is_iterable([1,2,3]) is True
    assert check_is_iterable(1) is False
github telegraphic / hickle / tests / test_hickle_helpers.py View on Github external
def test_check_is_iterable():
    assert check_is_iterable([1,2,3]) is True
    assert check_is_iterable(1) is False
github telegraphic / hickle / hickle / hickle.py View on Github external
# 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)