dispel.utils module#

General utility functions.

dispel.utils.camel_to_snake_case(value)[source]#

Transform the camel case string into a snake one.

Parameters:

value (str) – The string to process

Returns:

The passed string in lower case camel format.

Return type:

str

Raises:

TypeError – When the given value is not a string.

dispel.utils.convert_column_types(data, column_type_fetcher)[source]#

Convert columns of a pandas data frame to their indicated types.

Parameters:
  • data (DataFrame) – The data frame to be converted

  • column_type_fetcher (Callable[[Any], str]) – A function that retrieves the column type given its name.

Returns:

A pandas data frame containing the converted columns.

Return type:

pandas.DataFrame

dispel.utils.drop_none(data)[source]#

Drop None elements from a list.

Parameters:

data (List[Any]) –

Return type:

List[Any]

class dispel.utils.multidispatchmethod[source]#

Bases: object

Multi-dispatch generic method descriptor.

__init__(func)[source]#
Parameters:

func (Callable[[...], Any]) –

register(cls, method=None)[source]#

Register the method.

dispel.utils.plural(single, count, multiple=None)[source]#

Associate the word with its count.

Parameters:
  • single (str) – The single word.

  • count (int) – The count of the given count.

  • multiple (str | None) – The plural word of single if it shouldn’t just end with an s.

Returns:

Its associated plural.

Return type:

str

dispel.utils.raise_multiple_errors(errors)[source]#

Re-raise multiple exceptions one after the other.

Parameters:

errors (List[Exception]) – List of exceptions to raise

Raises:

Exception – The exceptions given as input

dispel.utils.set_attributes_from_kwargs(obj, *attrs, pop=True, **kwargs)[source]#

Set attributes in object from kwargs.

Parameters:
  • obj (object) – The class object where the attributes are to be set.

  • attrs (str) – The names of teh attributes that are to be set in the object.

  • pop (bool) – True if the attributes are to popped from the provided keyword arguments. False otherwise.

  • kwargs – The keyword argument from which the attributes are to be retrieved as well. If no values corresponding to the provided attributes are found a None value is set instead.

Returns:

A dictionary of the remaining key word arguments.

Return type:

Dict[str, Any]

dispel.utils.to_camel_case(value)[source]#

Transform a string into a camel case string.

Parameters:

value (str) – The string to process.

Returns:

The passed string in camel case format.

Return type:

str