Input data validations

Module containing base QC which call multiple QC functions and could be applied on a DataBundle.

marine_qc.validations.is_func_param(func, param)[source]

Return True if param is the name of a parameter of function func.

Parameters:
  • func (Callable) – Function whose parameters are to be inspected.

  • param (str) – Name of the parameter.

Return type:

bool

Returns:

bool – Returns True if param is one of the functions parameters or the function uses **kwargs.

marine_qc.validations.is_in_data(name, data)[source]

Return True if named column or variable, name, is in data.

Parameters:
  • name (str) – Name of variable.

  • data (pd.Series or pd.DataFrame) – Pandas Series or DataFrame to be tested.

Return type:

bool

Returns:

bool – Returns True if name is one of the columns or variables in data, False otherwise.

Raises:

TypeError – If data type is not pd.Series or pd.DataFrame.

marine_qc.validations.validate_arg(key, value, func_name, parameters, type_hints, reserved_keys, has_arguments)[source]

Validate argument against a function’s signature, taking decorators into account.

Parameters:
  • key (str) – The name of the argument to validate.

  • value (Any) – The value of the argument to validate.

  • func_name (str) – The name of the function (used in error message).

  • parameters (Mapping[str, inspect.Parameter]) – A mapping of parameter names to inspect.Parameter objects, typically from inspect.signature(func).parameters.

  • type_hints (Mapping[str, type]) – A mapping of parameter names to expected types, typically from typing.get_type_hints(func).

  • reserved_keys (set[str]) – Argument names that are considered reserved and should nor raise errors.

  • has_arguments (bool) – Whether the function accepts arbitrary arguments.

Return type:

None

marine_qc.validations.validate_args(func, args=None, kwargs=None)[source]

Validate positional and keyword arguments against a function’s signature, taking decorators into account.

This function checks that: - All provided keyword arguments correspond to valid parameters of the given function. - All required parameters of the function (i.e., parameters without default values) are present in the provided keyword arguments.

Parameters:
  • func (Callable[..., Any]) – The function whose signature is used for validation.

  • args (Sequence[Any], optional) – Sequence of arguments intended to be passed to func.

  • kwargs (Mapping[str, Any], optional) – Dictionary of keyword arguments intended to be passed to func.

Raises:
  • ValueError – If kwargs contains a key that is not a parameter of func.

  • TypeError – If a required parameter of func is missing from kwargs.

Return type:

None

marine_qc.validations.validate_dict(input_dict)[source]

Validate that the input is a dictionary with string keys and dictionary values.

This function checks that: - input_dict is a dictionary. - All keys in the dictionary are strings. - All top-level values in the dictionary are themselves dictionaries.

Parameters:

input_dict (Mapping[str, Mapping[str, Any]]) – The object to validate.

Raises:

TypeError – If input_dict is not a dictionary, if any key is not a string, or if any value is not a dictionary.

Return type:

None

marine_qc.validations.validate_type(value, expected)[source]

Recursively validate that a value matches the expected type hint.

Parameters:
  • value (Any) – The value to validate.

  • expected (Any) – The expected value type for validation.

Return type:

bool

Returns:

bool

  • True if type of value does match expected.

  • False if type of value does not match expected.