Transformation functions¶
- giskard.transformation_function(_fn: Callable[[...], Series | DataFrame] | Type[TransformationFunction] | None = None, row_level=True, cell_level=False, name=None, tags: List[str] | None = None, needs_dataset=False)[source]¶
Decorator that registers a function as a transformation function and returns a TransformationFunction instance. It can be used for transforming datasets in a specific way during testing.
- Parameters:
_fn – function to decorate. No need to provide this argument, the decorator will automatically take as input the function to decorate.
name – Optional name to use for the function when registering it.
tags – Optional list of tags to use when registering the function.
row_level – Whether to apply the transformation function row-wise (default) or on the full dataframe. If row_level is True, the slicing function will receive a row (either a Series or DataFrame), and if False, it will receive the entire dataframe.
cell_level – Whether to apply the transformation function on the cell level. If True, the slicing function will be applied to individual cells instead of rows or the entire dataframe.
- Returns:
The wrapped function or a new instance of TransformationFunction.
- class giskard.registry.transformation_function.TransformationFunction(func: Callable[[...], Series | DataFrame] | None, row_level=True, cell_level=False, needs_dataset=False)[source]¶
- execute(data: Series | DataFrame) Series | DataFrame [source]¶
_summary_
- Parameters:
data (Union[pd.Series, pd.DataFrame]) – _description_
- Returns:
_description_
- Return type:
Union[pd.Series, pd.DataFrame]
- upload(client: GiskardClient, project_key: str, uploaded_dependencies: Set[Artifact] | None = None) str [source]¶
Uploads the slicing function and its metadata to the Giskard hub.
- Parameters:
client (GiskardClient) – The Giskard client instance used for communication with the hub.
project_key (Optional[str]) – The project key where the slicing function will be uploaded. If None, the function will be uploaded to the global scope. Defaults to None.
- Returns:
The UUID of the uploaded slicing function.
- Return type:
str
- classmethod download(uuid: str, client: GiskardClient, project_key: str) Artifact [source]¶
Downloads the artifact from the Giskard hub or retrieves it from the local cache.
- Parameters:
uuid (str) – The UUID of the artifact to download.
client (GiskardClient) – The Giskard client instance used for communication with the hub.
project_key (Optional[str]) – The project key where the artifact is located. If None, the artifact will be retrieved from the global scope. Defaults to None.
- Returns:
The downloaded artifact.
- Return type:
Artifact
- Raises:
AssertionError – If the artifact metadata cannot be retrieved.
AssertionError – If the artifact is not found in the cache and the Giskard client is None.
Textual transformation functions¶
- giskard.functions.transformation.keyboard_typo_transformation(rate: SuiteInput | float | None = 0.1) TransformationFunction ¶
Generate a random typo from words of the text of ‘column_name’ Typos are generated through character substitution based on keyboard proximity
- giskard.functions.transformation.text_uppercase(column: SuiteInput | str | None = None) TransformationFunction ¶
- giskard.functions.transformation.text_lowercase(column: SuiteInput | str | None = None) TransformationFunction ¶
- giskard.functions.transformation.text_title_case(column: SuiteInput | str | None = None) TransformationFunction ¶
- giskard.functions.transformation.text_typo(column: SuiteInput | str | None = None, rate: SuiteInput | float | None = 0.05, min_length: SuiteInput | int | None = 10, rng_seed: SuiteInput | int | None = 1729) TransformationFunction ¶
- giskard.functions.transformation.text_typo_from_ocr(column: SuiteInput | str | None = None, rate: SuiteInput | float | None = 0.05, min_length: SuiteInput | int | None = 10, rng_seed: SuiteInput | int | None = 1729) TransformationFunction ¶
- giskard.functions.transformation.text_punctuation_removal(column: SuiteInput | str | None = None) TransformationFunction ¶
- giskard.functions.transformation.text_accent_removal(column: SuiteInput | str | None = None, rate: SuiteInput | float | None = 1.0, rng_seed: SuiteInput | int | None = 1729) TransformationFunction ¶
- giskard.functions.transformation.text_gender_switch(column: SuiteInput | str | None = None) TransformationFunction ¶
- giskard.functions.transformation.text_number_to_word(column: SuiteInput | str | None = None) TransformationFunction ¶
- giskard.functions.transformation.text_religion_switch(column: SuiteInput | str | None = None) TransformationFunction ¶
- giskard.functions.transformation.text_nationality_switch(column: SuiteInput | str | None = None) TransformationFunction ¶
- giskard.functions.transformation.text_typo_from_speech(column: SuiteInput | str | None = None, rng_seed: SuiteInput | int | None = 1729, min_length: SuiteInput | int | None = 10) TransformationFunction ¶
Special transformations used by the scan¶
- class giskard.scanner.robustness.text_transformations.TextAccentRemovalTransformation(column, rate=1.0, rng_seed=1729)[source]¶
Bases:
TextTransformation
- class giskard.scanner.robustness.text_transformations.TextFromOCRTypoTransformation(column, rate=0.05, min_length=10, rng_seed=1729)[source]¶
Bases:
TextTransformation
- class giskard.scanner.robustness.text_transformations.TextFromSpeechTypoTransformation(column, rng_seed=1729, min_length=10)[source]¶
- class giskard.scanner.robustness.text_transformations.TextGenderTransformation(column, rng_seed=1729)[source]¶
- class giskard.scanner.robustness.text_transformations.TextLanguageBasedTransformation(column, rng_seed=1729)[source]¶
Bases:
TextTransformation
- class giskard.scanner.robustness.text_transformations.TextLowercase(column, needs_dataset=False)[source]¶
Bases:
TextTransformation
- class giskard.scanner.robustness.text_transformations.TextNationalityTransformation(column, rng_seed=1729)[source]¶
- class giskard.scanner.robustness.text_transformations.TextNumberToWordTransformation(column, rng_seed=1729)[source]¶
- class giskard.scanner.robustness.text_transformations.TextPunctuationRemovalTransformation(*args, **kwargs)[source]¶
Bases:
TextTransformation
- class giskard.scanner.robustness.text_transformations.TextReligionTransformation(column, rng_seed=1729)[source]¶
- class giskard.scanner.robustness.text_transformations.TextTitleCase(column, needs_dataset=False)[source]¶
Bases:
TextTransformation
- class giskard.scanner.robustness.text_transformations.TextTransformation(column, needs_dataset=False)[source]¶
Bases:
TransformationFunction
- class giskard.scanner.robustness.text_transformations.TextTypoTransformation(column, rate=0.05, min_length=10, rng_seed=1729)[source]¶
Bases:
TextTransformation
- class giskard.scanner.robustness.text_transformations.TextUppercase(column, needs_dataset=False)[source]¶
Bases:
TextTransformation