wildboar.utils.validation#

Module Contents#

Functions#

check_X_y(x, y, *[, dtype, order, copy, ensure_2d, ...])

check_array(array, *[, dtype, order, copy, ravel_1d, ...])

Delegate array validation to scikit-learn

check_option(dict, key, name)

check_type(x, name, target_type[, required])

Check that the type of x is of a target type.

wildboar.utils.validation.check_X_y(x, y, *, dtype=float, order='C', copy=False, ensure_2d=True, allow_3d=False, allow_nd=False, force_all_finite=True, multi_output=False, ensure_min_samples=1, ensure_min_timesteps=1, ensure_min_dims=1, allow_eos=False, y_numeric=False, y_contiguous=True, estimator=None)[source]#
wildboar.utils.validation.check_array(array, *, dtype='numeric', order='C', copy=False, ravel_1d=False, ensure_2d=True, allow_3d=False, allow_nd=False, force_all_finite=True, ensure_min_samples=1, ensure_min_timesteps=1, ensure_min_dims=1, estimator=None, input_name='', allow_eos=False)[source]#

Delegate array validation to scikit-learn sklearn.utils.validation.check_array() with wildboar defaults and conventions.

  • we optionally allow end-of-sequence identifiers

  • by default we convert arrays to c-order

  • we optionally specifically allow for 3d-arrays

  • we never allow for sparse arrays

By default, the input is checked to be a non-empty 2D array in c-order containing only finite values, with at least 1 sample, 1 timestep and 1 dimension. If the dtype of the array is object, attempt converting to float, raising on failure.

Parameters:
  • array (object) – Input object to check / convert.

  • dtype ('numeric', type, list of type or None, optional) – Data type of result. If None, the dtype of the input is preserved. If “numeric”, dtype is preserved unless array.dtype is object. If dtype is a list of types, conversion on the first type is only performed if the dtype of the input is not in the list.

  • order ({'F', 'C'} or None, optional) – Whether an array will be forced to be fortran or c-style. When order is None, then if copy=False, nothing is ensured about the memory layout of the output array; otherwise (copy=True) the memory layout of the returned array is kept as close as possible to the original array.

  • copy (bool, optional) – Whether a forced copy will be triggered. If copy=False, a copy might be triggered by a conversion.

  • ravel_1d (bool, optional) – Whether to ravel 1d arrays or column vectors, it the array is neither an error is raised.

  • ensure_2d (bool, optional) – Whether to raise a value error if array is not 2D.

  • allow_3d (bool, optional) – Wheter to allow array.ndim == 3

  • allow_nd (bool, optional) – Whether to allow array.ndim > 2.

  • force_all_finite (bool or 'allow-nan', default=True) –

    Whether to raise an error on np.inf, np.nan, pd.NA in array. The possibilities are:

    • True: Force all values of array to be finite.

    • False: accepts np.inf, np.nan, pd.NA in array.

    • ’allow-nan’: accepts only np.nan and pd.NA values in array. Values cannot be infinite.

    If allow_eos=True, -np.inf is allowed despite force_all_finite=True.

  • ensure_min_samples (int, optional) – Make sure that the array has a minimum number of samples in its first axis (rows for a 2D array). Setting to 0 disables this check.

  • ensure_min_timesteps (int, optional) – Make sure that the 2D array has some minimum number of timesteps (columns). The default value of 1 rejects empty datasets. This check is only enforced when the input data has effectively 2 dimensions or is originally 1D and ensure_2d is True. Setting to 0 disables this check.

  • ensure_min_dims (int, optional) – Make sure that the array has a minimum number of dimensions. Setting to 0 disables this check.

  • estimator (str or estimator instance, default=None) – If passed, include the name of the estimator in warning messages.

  • input_name (str, default="") – The data name used to construct the error message.

Returns:

array_converted – The converted and validated array.

Return type:

object

wildboar.utils.validation.check_option(dict, key, name)[source]#
wildboar.utils.validation.check_type(x, name, target_type, required=True)[source]#

Check that the type of x is of a target type.

Parameters:
  • x (object) – The object to check.

  • name (str) – The name of the parameter.

  • target_type (type or tuple) – The required type(s) of x.

  • required (bool, optional) – If required=False, None is an allowed.