Skip to content

Commit

Permalink
🦉 Updates from OwlBot post-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] committed Jun 21, 2023
1 parent 85ac76d commit 85c62be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 6 additions & 10 deletions dlp/snippets/deid.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def deidentify_with_time_extract(
input_csv_file: str,
output_csv_file: str,
) -> None:
""" Uses the Data Loss Prevention API to deidentify dates in a CSV file through
"""Uses the Data Loss Prevention API to deidentify dates in a CSV file through
time part extraction.
Args:
project: The Google Cloud project id to use as a parent resource.
Expand Down Expand Up @@ -968,9 +968,7 @@ def map_data(value):
try:
date = datetime.strptime(value, "%m/%d/%Y")
return {
"date_value": {
"year": date.year, "month": date.month, "day": date.day
}
"date_value": {"year": date.year, "month": date.month, "day": date.day}
}
except ValueError:
return {"string_value": value}
Expand All @@ -995,9 +993,7 @@ def map_rows(row):
"field_transformations": [
{
"primitive_transformation": {
"time_part_config": {
"part_to_extract": "YEAR"
}
"time_part_config": {"part_to_extract": "YEAR"}
},
"fields": date_fields,
}
Expand Down Expand Up @@ -2266,14 +2262,14 @@ def deidentify_table_with_multiple_crypto_hash(
time_extract_parser.add_argument(
"input_csv_file",
help="The path to the CSV file to deidentify. The first row of the "
"file must specify column names, and all other rows must contain "
"valid values.",
"file must specify column names, and all other rows must contain "
"valid values.",
)
time_extract_parser.add_argument(
"date_fields",
nargs="+",
help="The list of date fields in the CSV file to de-identify. Example: "
"['birth_date', 'register_date']",
"['birth_date', 'register_date']",
)
time_extract_parser.add_argument(
"output_csv_file", help="The path to save the time-extracted data."
Expand Down
4 changes: 3 additions & 1 deletion dlp/snippets/deid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ def test_deidentify_with_date_shift_using_context_field(
assert "Successful" in out


def test_deidentify_with_time_extract(tempdir: TextIO, capsys: pytest.CaptureFixture) -> None:
def test_deidentify_with_time_extract(
tempdir: TextIO, capsys: pytest.CaptureFixture
) -> None:
output_filepath = os.path.join(str(tempdir), "year-extracted.csv")

deid.deidentify_with_time_extract(
Expand Down

0 comments on commit 85c62be

Please sign in to comment.