Miscallaneous utility functions for the psyplot package.
Classes:
|
An ordered |
Functions:
|
Checks whether the key is in a list of possible keys |
|
|
|
Test if val is hashable and if not, get it's string representation |
|
Test if an object is iterable |
|
|
|
|
|
Join multiple dictionaries into one |
|
This utility function gets the entry points of the psyplot plugins |
|
Function to sort keyword arguments and sort them into dictionaries |
|
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
- 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.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.join_dicts(dicts, delimiter=None, keep_all=False)[source]
Join multiple dictionaries into one
- Parameters:
- Returns:
The combined dictionary
- Return type:
- 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:
- 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