stems.utils module¶
-
class
stems.utils.
FrozenKeyDict
(*args, **kwds)[source]¶ Bases:
collections.abc.MutableMapping
A dict that doesn’t allow new keys
-
stems.utils.
concat_lists
(l)[source]¶ Concatenate all list-like items in
l
See also
toolz.concat()
Similar function, but concatenates all iterables
flatten_lists()
Recursive version of this function
-
stems.utils.
dtype_info
(arr)[source]¶ Return integer or float dtype info
- Parameters
arr (np.ndarray) – Array
- Returns
NumPy type information
- Return type
numpy.core.getlimits.finfo or numpy.core.getlimits.iinfo
- Raises
TypeError – Raised if
arr
is not a int or float type
-
stems.utils.
find
(location, pattern, regex=False)[source]¶ Return a sorted list of files matching pattern
- Parameters
location (str or pathlib.Path) – Directory location to search
pattern (str) – Search pattern for files
regex (bool) – True if
pattern
is a regular expression
- Returns
List of file paths for files found
- Return type
-
stems.utils.
find_subclasses
(cls_)[source]¶ Find subclasses of an object
- Parameters
cls_ (class) – A Python class
- Returns
Classes that inherit from
cls_
- Return type
set[class]
-
stems.utils.
list_like
(obj)[source]¶ Return True if
obj
is list-likeList-like includes lists, tuples, and numpy.ndarrays, but not other sequences like str or Mapping.
-
stems.utils.
np_promote_all_types
(*dtypes)[source]¶ Return the largest NumPy datatype required to hold all types
- Parameters
dtypes (iterable) – NumPy datatypes to promote
- Returns
Smallest NumPy datatype required to store all input datatypes
- Return type
np.dtype
See also
np.promote_types()
-
stems.utils.
register_multi_singledispatch
(func, types)[source]¶ Register multiple types for singledispatch
- Parameters
func (callable) – Function
types (tuple) – Multiple types to register
- Returns
func – Decorated function
- Return type
callable
-
stems.utils.
renamed_upon_completion
(destination, tmpdir=None, prefix='', suffix=None)[source]¶ Help save/write to file and move upon completion
- Parameters
destination (str or Path) – The final intended location of the file
tmpdir (str, optional) – By default, this function will yield a temporary filename in the same directory as
destination
, but you may specify another location usingtmpdir
.prefix (str, optional) – Characters to prefix the temporary file with
suffix (str, optional) – Characters to add at the end of the temporary filename. By default appends “.tmp.” and the process ID
- Yields
str – A temporary filename to use during writing/saving/etc