Utility Functions

Utility functions for the owimetadatabase_preprocessor package.

owimetadatabase_preprocessor.utility.utils.custom_formatwarning(message, category, filename, lineno, line=None)

Custom format for warnings.

owimetadatabase_preprocessor.utility.utils.dict_generator(dict_: Dict[str, Any], keys_: List[str] = [], method_: str = 'exclude') Dict[str, Any]

Generate a dictionary with the specified keys.

Parameters:
  • dict – Dictionary to be filtered.

  • keys – List of keys to be included or excluded.

  • method – Method to be used for filtering. Options are “exclude” and “include”.

Returns:

Filtered dictionary.

owimetadatabase_preprocessor.utility.utils.compare_if_simple_close(a: Any, b: Any, tol: float = 1e-09) Tuple[bool, None | str]

Compare two values and return a boolean and a message.

Parameters:
  • a – First value to be compared.

  • b – Second value to be compared.

  • tol – Tolerance for the comparison.

Returns:

Tuple with a result of comparison and a message if different.

owimetadatabase_preprocessor.utility.utils.check_df_eq(df1: DataFrame, df2: DataFrame, tol: float = 1e-09) bool

Check if two dataframes are equal.

Parameters:
  • df1 – First dataframe to be compared.

  • df2 – Second dataframe to be compared.

  • tol – Tolerance for the comparison.

Returns:

Boolean indicating if the dataframes are equal.

owimetadatabase_preprocessor.utility.utils.deepcompare(a: Any, b: Any, tol: float = 1e-05) Tuple[bool, None | str]

Compare two complicated (potentailly nested) objects recursively and return a result and a message.

Parameters:
  • a – First object to be compared.

  • b – Second object to be compared.

  • tol – Tolerance for the comparison.

Returns:

Tuple with a result of comparison and a message if different.

owimetadatabase_preprocessor.utility.utils.fix_nan(obj: Any) Any

Replace “nan” strings with None.

Parameters:

obj – Object to be fixed.

Returns:

Fixed object.

owimetadatabase_preprocessor.utility.utils.fix_outline(data: Any) Any

Fix the outline attribute in the data.

Parameters:

data – Data to be fixed.

Returns:

Fixed data.

owimetadatabase_preprocessor.utility.utils.hex_to_dec(value)

Return [red, green, blue, alpha] for the color given as #rrggbbaa.