Skip to content

Commit c529547

Browse files
committed
minor tweaks for datetime and gemini comments
1 parent 4db9046 commit c529547

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

sdks/python/apache_beam/yaml/yaml_mapping.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import datetime
2121
import itertools
22-
import json
2322
import re
2423
import threading
2524
import uuid
@@ -225,8 +224,13 @@ def js_to_py(obj):
225224
return obj
226225
elif isinstance(obj, Mapping):
227226
return {k: js_to_py(v) for k, v in obj.items()}
228-
elif not isinstance(obj, str) and isinstance(obj, Iterable):
227+
elif not isinstance(obj, (str, bytes)) and isinstance(obj, Iterable):
229228
return [js_to_py(v) for v in obj]
229+
elif isinstance(obj, str):
230+
try:
231+
return datetime.datetime.fromisoformat(obj)
232+
except ValueError:
233+
return obj
230234
else:
231235
return obj
232236

sdks/python/apache_beam/yaml/yaml_udf_test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,10 @@ def test_map_to_fields_js_date(self):
394394
}
395395
''')
396396

397-
expected_date = '2026-04-17T18:00:00.000Z'
397+
expected_date = datetime.datetime(
398+
2026, 4, 17, 18, tzinfo=datetime.timezone.utc)
398399

399-
assert_that(
400-
result | as_rows(), equal_to([
401-
beam.Row(date=expected_date),
402-
]))
400+
assert_that(result | as_rows(), equal_to([beam.Row(date=expected_date)]))
403401

404402

405403
if __name__ == '__main__':

0 commit comments

Comments
 (0)