Skip to content

Commit 5617e88

Browse files
1 parent bdeaf5a commit 5617e88

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

‎dlp/snippets/deid.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ def deidentify_with_time_extract(
928928
input_csv_file: str,
929929
output_csv_file: str,
930930
) -> None:
931-
""" Uses the Data Loss Prevention API to deidentify dates in a CSV file through
931+
"""Uses the Data Loss Prevention API to deidentify dates in a CSV file through
932932
time part extraction.
933933
Args:
934934
project: The Google Cloud project id to use as a parent resource.
@@ -968,9 +968,7 @@ def map_data(value):
968968
try:
969969
date = datetime.strptime(value, "%m/%d/%Y")
970970
return {
971-
"date_value": {
972-
"year": date.year, "month": date.month, "day": date.day
973-
}
971+
"date_value": {"year": date.year, "month": date.month, "day": date.day}
974972
}
975973
except ValueError:
976974
return {"string_value": value}
@@ -995,9 +993,7 @@ def map_rows(row):
995993
"field_transformations": [
996994
{
997995
"primitive_transformation": {
998-
"time_part_config": {
999-
"part_to_extract": "YEAR"
1000-
}
996+
"time_part_config": {"part_to_extract": "YEAR"}
1001997
},
1002998
"fields": date_fields,
1003999
}
@@ -2266,14 +2262,14 @@ def deidentify_table_with_multiple_crypto_hash(
22662262
time_extract_parser.add_argument(
22672263
"input_csv_file",
22682264
help="The path to the CSV file to deidentify. The first row of the "
2269-
"file must specify column names, and all other rows must contain "
2270-
"valid values.",
2265+
"file must specify column names, and all other rows must contain "
2266+
"valid values.",
22712267
)
22722268
time_extract_parser.add_argument(
22732269
"date_fields",
22742270
nargs="+",
22752271
help="The list of date fields in the CSV file to de-identify. Example: "
2276-
"['birth_date', 'register_date']",
2272+
"['birth_date', 'register_date']",
22772273
)
22782274
time_extract_parser.add_argument(
22792275
"output_csv_file", help="The path to save the time-extracted data."

‎dlp/snippets/deid_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ def test_deidentify_with_date_shift_using_context_field(
230230
assert "Successful" in out
231231

232232

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

236238
deid.deidentify_with_time_extract(

0 commit comments

Comments
 (0)