Miscallaneous utility functions for the psyplot package.

Classes:

Defaultdict([default_factory])

An ordered collections.defaultdict

Functions:

check_key(key, possible_keys[, raise_error, ...])

Checks whether the key is in a list of possible keys

get_default_value(func, arg)

hashable(val)

Test if val is hashable and if not, get it's string representation

is_iterable(iterable)

Test if an object is iterable

is_remote_url(path)

isstring(s)

join_dicts(dicts[, delimiter, keep_all])

Join multiple dictionaries into one

plugin_entrypoints([group, name])

This utility function gets the entry points of the psyplot plugins

sort_kwargs(kwargs, *param_lists)

Function to sort keyword arguments and sort them into dictionaries

unique_everseen(iterable[, key])

List unique elements, preserving order.

class psyplot.utils.Defaultdict(default_factory=None, *a, **kw)[source]

Bases: dict

An ordered collections.defaultdict

Taken from http://stackoverflow.com/a/6190500/562769

Methods:

copy()

Return a shallow copy of the dictionary

copy()[source]

Return a shallow copy of the dictionary

psyplot.utils.check_key(key, possible_keys, raise_error=True, name='formatoption keyword', msg='See show_fmtkeys function for possible formatopion keywords', *args, **kwargs)[source]

Checks whether the key is in a list of possible keys

This function checks whether the given key is in possible_keys and if not looks for similar sounding keys

Parameters:
  • key (str) – Key to check

  • possible_keys (list of strings) – a list of possible keys to use

  • raise_error (bool) – If not True, a list of similar keys is returned

  • name (str) – The name of the key that shall be used in the error message

  • msg (str) – The additional message that shall be used if no close match to key is found

  • *args – They are passed to the difflib.get_close_matches() function (i.e. n to increase the number of returned similar keys and cutoff to change the sensibility)

  • **kwargs – They are passed to the difflib.get_close_matches() function (i.e. n to increase the number of returned similar keys and cutoff to change the sensibility)

Returns:

  • str – The key if it is a valid string, else an empty string

  • list – A list of similar formatoption strings (if found)

  • str – An error message which includes

Raises:

KeyError – If the key is not a valid formatoption and raise_error is True

psyplot.utils.get_default_value(func, arg)[source]
psyplot.utils.hashable(val)[source]

Test if val is hashable and if not, get it’s string representation

Parameters:

val (object) – Any (possibly not hashable) python object

Returns:

The given val if it is hashable or it’s string representation

Return type:

val or string

psyplot.utils.is_iterable(iterable)[source]

Test if an object is iterable

Parameters:

iterable (object) – The object to test

Returns:

True, if the object is an iterable object

Return type:

bool

psyplot.utils.is_remote_url(path)[source]
psyplot.utils.isstring(s)[source]
psyplot.utils.join_dicts(dicts, delimiter=None, keep_all=False)[source]

Join multiple dictionaries into one

Parameters:
  • dicts (list of dict) – A list of dictionaries

  • delimiter (str) – The string that shall be used as the delimiter in case that there are multiple values for one attribute in the arrays. If None, they will be returned as sets

  • keep_all (bool) – If True, all formatoptions are kept. Otherwise only the intersection

Returns:

The combined dictionary

Return type:

dict

psyplot.utils.plugin_entrypoints(group='psyplot', name='name')[source]

This utility function gets the entry points of the psyplot plugins

psyplot.utils.sort_kwargs(kwargs, *param_lists)[source]

Function to sort keyword arguments and sort them into dictionaries

This function returns dictionaries that contain the keyword arguments from kwargs corresponding given iterables in *params

Parameters:
  • kwargs (dict) – Original dictionary

  • *param_lists – iterables of strings, each standing for a possible key in kwargs

Returns:

len(params) + 1 dictionaries. Each dictionary contains the items of kwargs corresponding to the specified list in *param_lists. The last dictionary contains the remaining items

Return type:

list

psyplot.utils.unique_everseen(iterable, key=None)[source]

List unique elements, preserving order. Remember all elements ever seen.

Function taken from https://docs.python.org/2/library/itertools.html