tools.helpers package

Subpackages

Module contents

Helpers.

tools.helpers.isiterable(obj)

Returns whether an object is “iterable” or not. Are considered iterable tuple, list, set and inherited classes

tools.helpers.isinstance_filetypes(filetypes)

Returns True if ‘filetypes’ is a valid variable for filetypes argument in tkinter.filedialog functions, else False.

tools.helpers.isinlist(obj, iterable)

Returns whether an object is in the iterable or not.

Support is granted for numpy and pandas objects which have multiple definitions of truth. One numpy/pandas object is considered in the iterable if the object itself is in the iterable. Therefore, if a copy but not the object is present in the iterable, isinlist returns False.

>>> df = pd.DataFrame()
>>> ls = [5, 'a', np.array([5, 4]), df]
>>> isinlist(5, ls), isinlist(6, ls), isinlist('a', ls), isinlist('b', ls)
(True, False, True, False)
>>> isinlist(df, ls), isinlist(df.copy(), ls), isinlist(np.array([5, 4]), ls)
(True, False, False)