whylogs.util.data
¶
Utility functions for interacting with data
Module Contents¶
Functions¶
|
get an attribute (from an object) or key (from a dict-like object) |
|
Flatten a nested dictionary/object according to a specified name mapping. |
|
|
Return the given string converted to a string that can be used for a clean |
- whylogs.util.data.getter(x, k: str, *args)¶
get an attribute (from an object) or key (from a dict-like object)
getter(x, k) raise KeyError if k not present
getter(x, k, default) return default if k not present
This is a convenience function that allows you to interact the same with an object or a dictionary
- Parameters
x (object, dict) – Item to get attribute from
k (str) – Key or attribute name
default (optional) – Default value if k not present
- Returns
val – Associated value
- Return type
object
- whylogs.util.data.remap(x, mapping: dict)¶
Flatten a nested dictionary/object according to a specified name mapping.
- Parameters
x (object, dict) –
An object or dict which can be treated as a nested dictionary, where attributes can be accessed as:
attr = x.a.b[‘key_name’][‘other_Name’].d
- Indexing list values is not implemented, e.g.:
x.a.b[3].d[‘key_name’]
mapping (dict) –
Nested dictionary specifying the mapping. ONLY values specified in the mapping will be returned. For example:
{'a': { 'b': { 'c': 'new_name' } }
could flatten x.a.b.c or x.a[‘b’][‘c’] to x[‘new_name’]
- Returns
flat – A flattened ordered dictionary of values
- Return type
OrderedDict
- whylogs.util.data._remap(x, mapping: dict, y: dict)¶
- whylogs.util.data.get_valid_filename(s)¶
Return the given string converted to a string that can be used for a clean filename. Remove leading and trailing spaces; convert other spaces to underscores; and remove anything that is not an alphanumeric, dash, underscore, or dot.
>>> from whylogs.util.data import get_valid_filename >>> get_valid_filename(" Background of tim's 8/1/2019 party!.jpg ")