Utilities¶
Library-specific¶
Dataframe Manipulation¶
Dataframe manipulation utility functions.
- common_rows(child: DataFrame, parent: DataFrame, child_on: Any | None = None, parent_on: Any | None = None) Series [source]¶
Return boolean mask where True if record common in Child and Parent.
- Parameters:
child (pd.DataFrame) – The child dataframe.
parent (pd.DataFrame) – The parent dataframe.
child_on (Any) – Column or index level names in child to join on.
parent_on (Any) – Column or index level names in parent to join on.
- Returns:
A Boolean series indicating common rows.
- Return type:
pd.Series
- convert_column_type(series: Series, type_string: str, **kwargs) Series [source]¶
Convert series to pandas dtype specified in type string representation.
- Parameters:
series (pd.Series) – Series for which the dtype has to set.
type_string (str) – Supported dtype to which the series will be converted.
kwargs (key, value mappings) – Other keyword arguments are passed down to pandas.to_datetime if the dtype is ‘datetime’.
- Returns:
The converted series with the appropriate dtype.
- Return type:
pd.Series
Logging¶
Logging utility functions.
- log_df(df: DataFrame, msg: str, hide: List[str] | str = [], level: int = 40, **kwargs) None [source]¶
Log DataFrame records with a message.
- Parameters:
df (pandas.DataFrame) – DataFrame to be logged.
msg (str) – Log message compatible with string formatting.
hide (list-like or scalar, optional) – Sensitive column or columns to hide.
level (int, optional) – Logging level to use. Accepts logging.LEVEL values.
kwargs (key, value mappings) – Other keyword arguments are passed to str.format().
- log_col(series: Series, msg: str, hide: bool = False, level: int = 40, **kwargs) None [source]¶
Log column values with a message.
- Parameters:
series (pd.Series) – Series to be logged.
msg (str) – Log message compatible with string formatting.
hide (bool, optional) – If True, hides the values of the series.
level (int, optional) – Logging level to use. Accepts logging.LEVEL values.
kwargs (key, value mappings) – Other keyword arguments are passed to str.format().
General-purpose¶
General-purpose utility functions.
- copy(src: str, dst: str, overwrite: bool = False) None [source]¶
Copy content from source path to destination path.
- deep_get(dictionary: Dict[Any, Any], keys: str, default: Any | None = None) Any [source]¶
dict.get() for nested dictionaries.
- denest_dict(dictionary: Dict[Any, Any]) Dict[Any, Any] [source]¶
Return denested dict with all nested elements removed.
- get_dir_contents(root: str, pattern: str, skip: List[str] | None = None) List[str] [source]¶
Return list of contents in a directory that match pattern.