openepda.main module
openepda.main.py
This module contains utility functions and openEPDA data file writer and loader.
Author: Dima Pustakhod Copyright: 2020–2022, TU/e - PITC and authors
- openepda.main.is_array_like(x)[source]
Check if a variable is array-like
- Returns
True if x is a tuple, a list, a numpy.ndarray, or a subclass of these; False otherwise
- Return type
bool
Examples
>>> i = 1; f = 1.1; st = 's'; bs = b'S' >>> d = {1: 1, 2: 2}; s = {1, 2, 3} >>> l = [1, 2]; t = (1, 2) >>> arr = np.asarray([1, 2, 3]); m = np.array([1, 2, 3]) >>> is_array_like(i), is_array_like(f) (False, False) >>> is_array_like(st), is_array_like(bs) (False, False) >>> is_array_like(d), is_array_like(s) (False, False) >>> is_array_like(l), is_array_like(t) (True, True) >>> is_array_like(arr), is_array_like(m) (True, True)
- openepda.main.is_list_or_tuple(x)[source]
Check if a variable is either a tuple or a list
- Returns
True if x is a tuple or list, or a subclass of these; False otherwise
- Return type
bool
Examples
>>> i = 1; f = 1.1; st = 's'; bs = b'S' >>> d = {1: 1, 2: 2}; s = {1, 2, 3} >>> l = [1, 2]; t = (1, 2) >>> arr = np.asarray([1, 2, 3]); m = np.array([1, 2, 3]) >>> is_list_or_tuple(i), is_list_or_tuple(f) (False, False) >>> is_list_or_tuple(st), is_list_or_tuple(bs) (False, False) >>> is_list_or_tuple(d), is_list_or_tuple(s) (False, False) >>> is_list_or_tuple(l), is_list_or_tuple(t) (True, True) >>> is_list_or_tuple(arr), is_list_or_tuple(m) (False, False)
- openepda.main.split_array_data(data, how='max_length')[source]
- Parameters
how (str) – ‘max_length|most_common’
Examples
>>> split_array_data({2: [1, 2], '2a': [1, 4]}) ({}, {2: [1, 2], '2a': [1, 4]})
>>> split_array_data({2: [1, 2], 3: [1, 2, 3], '3a': [1, 2, 4]}) ({2: [1, 2]}, {3: [1, 2, 3], '3a': [1, 2, 4]})
>>> split_array_data({2: [1, 2, 3], 3: [1, 2], '3a': [1, 2]}, how='most_common') ({2: [1, 2, 3]}, {3: [1, 2], '3a': [1, 2]})