Delete
delete.py removes existing rows from the dataset — the dual operation of Duplicated: instead of appending rows to grow the dataset, it drops rows to shrink it.
Function Signature
from pucktrick.deleted import delete_rows
error_code, modified_df = delete_rows(df, strategy)
# or, for mode="extended":
error_code, modified_df = delete_rows(df, strategy, original_df=clean_df)
Strategy Parameters
No module-specific parameters are required inside perturbate_data. Use the base strategy parameters to configure which rows to remove.
Example
from pucktrick.deleted import delete_rows
strategy = {
"affected_features": ["f1"],
"selection_criteria": "all",
"percentage": 0.2,
"mode": "new",
"perturbate_data": {"sampling": "random"}
}
error, D1 = delete_rows(df, strategy)
# Later, extend the cumulative deletion to 50% of the original rows
strategy_extended = {**strategy, "percentage": 0.5, "mode": "extended"}
error, D2 = delete_rows(D1, strategy_extended, original_df=df)
Modes
Only "new" and "extended" modes are supported — "composed" doesn't apply, since a deleted row leaves nothing behind to target.
| Mode | Behaviour |
|---|---|
new | Removes rows from the dataset up to the specified percentage. |
extended | Removes further rows from a dataset that has already had rows deleted, reaching the cumulative target. Since deleted rows can't be detected from the current dataframe the way modified-in-place rows can, the cumulative percentage is computed against the row count of original_df. Requires original_df. |