autom8qc.core
autom8qc.core.components
Note
In object-oriented programming, the open–closed principle states software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. Such an entity can allow its behaviour to be extended without modifying its source code.
The base components are dedicated to performing one specific task and don’t know anything about the context. They save the metadata and implements only one method. This approach ensures that they are flexible and can easily adapt. All components inherit from the abstract base class BaseComponent since they share the same properties (DRY). Moreover, the inherited components are abstract as well (Open-Closed) and can be customized.
BaseComponent
Note
Don’t repeat yourself (DRY, or sometimes do not repeat yourself) is a principle of software development aimed at reducing repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy.
- class autom8qc.core.components.BaseComponent
Bases:
abc.ABC
Abstract base class that defines the attributes for the base components. Each component has to provide its information (Name, Description, Supported parameters). The class provides the method check_metadata to check if the instance’s metadata is valid. Since all base components share the same attributes (NAME, DESCRIPTION, parameters), they have to inherit from this class. So you don’t have to implement the methods to check the metadata several times (DRY).
See also
autom8qc.core.parameters.ParameterList
- Parameters
NAME (str) – Name of the component
DESCRIPTION (str) – Description of the component
parameters (ParameterList) – Supported parameters (default: None)
- autom8qc.core.components.BaseComponent.check_metadata(self)
Checks if the defined metadata (NAME, DESCRIPTION, parameters) of the component is valid. If anything isn’t correctly defined, the method will raise an error for it.
Important
If you inherit from this class, make sure that call this method at the end of the constructor to validate the metadata of the instance.
- Raises
EmptyString – If NAME is not set or empty
InvalidType – If NAME is not a string
EmptyString – If DESCRIPTION is not set or empty
InvalidType – If DESCRIPTION is not a string
InvalidType – If parameters isn’t a ParameterList
InvalidValue – If an item in parameters is not a Parameter
- Returns
None
- Return type
None
autom8qc.core.exceptions
This module defines the exceptions that the framework will raise.
- exception autom8qc.core.exceptions.DoesNotExist
- exception autom8qc.core.exceptions.EmptyString
- exception autom8qc.core.exceptions.InvalidKey
- exception autom8qc.core.exceptions.InvalidType
- exception autom8qc.core.exceptions.InvalidValue
- exception autom8qc.core.exceptions.KeyAlreadyExists
- exception autom8qc.core.exceptions.NoItemsExist
- exception autom8qc.core.exceptions.NotSupportedType
- exception autom8qc.core.exceptions.RequiredParameter
autom8qc.core.parameters
This module provides the class Parameter to define parameters and the class to ParameterList to create a list of parameters. Several classes use a ParameterList to define the supported parameters. The first advantage of this approach is that you don’t have to check the types of the parameters by yourself. The second advantage is that you can handle the supported parameters of tests, functions, etc., in a standardized way. Especially when you want to integrate the framework in your system, you can access the parameters of different tests in a standardized way.
See also
autom8qc.measures.base.BaseRule
Parameter
- class autom8qc.core.parameters.Parameter(name, description, dtype, optional=False, value=None, default=None)
Bases:
object
An instance of the class stores the metadata (name, description, type) and the value of a parameter. You can create an instance of the class without setting the value since you usually define the supported parameters before you have the value itself. To make sure that required parameters have a valid value (e.g., when you initialize a test), you can use the method is_valid. Moreover, you can define a default value for the parameter.
- Parameters
name (str) – Name of the parameter
description (str) – Short description (optional)
dtype (type) – Data type of the parameter (e.g., float)
optional (bool) – Optional parameter (Default: False)
value (dtype) – Value of the parameter (Can be None if optional is True)
default (dtype) – Default value
- property default
Returns the default value of the parameter.
- Returns
Default value
- Return type
dtype
- is_valid()
Returns True if the value of the parameter is correctly set. A required parameter is valid if the value is set. Optional parameters can have None as value.
- Returns
True if parameter is valid, False otherwise.
- Return type
bool
- property json_format
Returns the value as a JSON string. For example, if the value is 42, the method returns {‘value’: 42}.
- Returns
Value as JSON format.
- Return type
str
- load_json(payload)
Loads the value from the given payload.
- Parameters
payload (str) – Payload
- Returns
None
- Return type
None
- property metadata
Returns all attributes in a dictionary.
- Returns
All attributes of the parameter
- Return type
dict
- property value
Returns the value of the parameter.
- Returns
Value of the parameter
- Return type
dtype
ParameterList
- class autom8qc.core.parameters.ParameterList(*items)
Bases:
object
An instance of the class represents a list to handle parameters. For performance reasons, the class uses a dictionary internally and handles the names in an own list. The idea is that the number of items will not change often. Usually, you define the supported parameters once, and after it, the length of the list items is constant. Moreover, you can access a list item easily by name and handle an instance of the class like a normal list (e.g., iterate, slicing, etc.,).
Warning
Note that the items will sort by name. Have this in mind if you want to access items with the list position.
See also
autom8qc.core.parameters.Parameter
- add(parameter)
Adds a parameter to the list. If a parameter with the same name already exists in the list, the method will raise a KeyError.
- Raises
KeyAlreadyExists – If a parameter with the name already exists
InvalidType – If parameter is not an instance of Parameter
- Parameters
parameter (Parameter) – Parameter
- Returns
None
- Return type
None
- check_parameters()
Checks if all parameters are valid. If parameter is not valid, a InvalidValue with a message that describes which parameter is not valid will raise.
- Raises
InvalidValue – If a parameter is not valid
- Returns
None
- Return type
None
- clear()
Deletes all items of the list.
- Returns
None
- Return type
None
- property values
Returns the values in a dictionary (key=name, value=value).
- Returns
Parameters
- Return type
dict
autom8qc.core.structures
This module provides data structures. Each structure inherits from the abstract class BaseStructure. With this approach, you can make sure that the framework can handle easily different structures and new structures can add without changing existing code. Moreover, it’s not possible to change the reference of the data afterward since the data is hidden for other modules. This avoids side effects and is less error-prone.
Warning
For performance reasons, the data will not be copied if it will requested. Therefore you have to be careful that you don’t override the data inside a test.
See also
BaseStructure
- class autom8qc.core.structures.BaseStructure(name, data)
Bases:
abc.ABC
Abstract class that defines the interface for each structure.
- Parameters
name (str) – Name to identify the data
data (dtype) – Data
dtype (object) – Class reference
DataFrame
- class autom8qc.core.structures.DataFrame(name, data)
Bases:
autom8qc.core.structures.BaseStructure
Structure to handle data frames.
- Parameters
name (str) – Name of the series
data (pd.Series) – Data points
Series
- class autom8qc.core.structures.Series(name, data)
Bases:
autom8qc.core.structures.BaseStructure
Structure to handle time series.
- Parameters
name (str) – Name of the series
data (pd.Series) – Data points
autom8qc.core.validities
This module provides the class Validity to define validities. Validities can be used instead of probabilities to mark the data point, for example, as invalid. Mapper and measures use validities.
See also
autom8qc.mappers.validities
Validity
- class autom8qc.core.validities.Validity(name, description, level)
Bases:
object
An instance of the class stores the metadata (name, description, level) of a validity.
- Parameters
name (str) – Name of the validitiy
description (str) – Short description (optional)
level (int) – Validity level (the higher the level, the worse the quality)
- static replace_by_levels(series, without_nan=False)
Replaces the validities in the series by theirs level. For example, the validity GOOD (see also StandardValidities) will be replaced by the 0. Optionally, you can use the parameter without_nan to delete the Missing values. This option requires that the missing validity has the name Missing value.
- Parameters
series (pd.Series) – Series with validities
- Returns
Series with the levels
- Return type
pd.Series
ValidityContainer
- class autom8qc.core.validities.ValidityContainer(good, limited, erroneous, not_validated, missing)
Bases:
object
Provides a container to manage validities.
Important
The levels of the validities describe the susceptibility of the points. The higher the level of the validity, the worse the quality.
See also
autom8qc.core.validities.Validity
- Parameters
GOOD (string) – Validity Good
LIMITED (string) – Validity Limited
ERRONEOUS (string) – Validity Erroneous
NOT_VALIDATED (string) – Validity Not validate
MISSING (string) – Validity Missing
- property ALL_VALIDITIES
Returns a dictionary with all validities. The keys are the levels of the validities.
- Returns
All validities
- Return type
dict
- property ERRONEOUS
Returns the validitiy ERRONEOUS.
- Returns
Validity ERRONEOUS
- Return type
Validity
- property GOOD
Returns the validitiy GOOD.
- Returns
Validity GOOD
- Return type
Validity
- property LIMITED
Returns the validitiy LIMITED.
- Returns
Validity LIMITED
- Return type
Validity
- property MISSING
Returns the validitiy MISSING.
- Returns
Validity MISSING
- Return type
Validity
- property NOT_VALIDATED
Returns the validitiy NOT_VALIDATED.
- Returns
Validity NOT_VALIDATED
- Return type
Validity
- replace_by_levels(series, without_nan=False)
Replaces the validities in the series by theirs level. For example, the validity GOOD (see also StandardValidities) will be replaced by the 0. Optional, you can use the parameter without_nan to delete the Missing values.
- Parameters
series (pd.Series) – Series with validities
- Returns
Series with the levels
- Return type
pd.Series