utility_functions.py 766 B

12345678910111213141516171819202122
  1. def pop_from_dict_by_set(dictionary: dict, valid_keys: set) -> dict:
  2. """ remove and create new dict with key value pairs of dictionary, where key is in valid_keys """
  3. new_dictionary = {}
  4. for key in list(dictionary.keys()):
  5. if key in valid_keys:
  6. new_dictionary[key] = dictionary.pop(key)
  7. return new_dictionary
  8. def check_kwargs_empty(kwargs_dict, raise_error=False) -> bool:
  9. """ returns True if kwargs are empty, False otherwise, raises error if not empty """
  10. if len(kwargs_dict) > 0:
  11. if raise_error:
  12. raise ValueError(f"{list(kwargs_dict.keys())} are not supported arguments. Look at the documentation for supported arguments.")
  13. else:
  14. return True
  15. else:
  16. return False