ebyhr commented on code in PR #3505:
URL: https://github.com/apache/iceberg-python/pull/3505#discussion_r3447756302
##########
tests/utils/test_datetime.py:
##########
@@ -130,6 +130,16 @@ def test_timestamptz_to_nanos(timestamp: str, nanos: int)
-> None:
assert nanos == timestamptz_to_nanos(timestamp)
+def test_timestamptz_to_nanos_missing_zone_offset() -> None:
+ with pytest.raises(ValueError, match="Missing zone offset:
2025-02-23T20:21:44.375612001"):
+ timestamptz_to_nanos("2025-02-23T20:21:44.375612001")
+
+
+def test_timestamp_to_nanos_unexpected_zone_offset() -> None:
+ with pytest.raises(ValueError, match="Zone offset provided, but not
expected: 2025-02-23T16:21:44.375612001-04:00"):
+ timestamp_to_nanos("2025-02-23T16:21:44.375612001-04:00")
Review Comment:
nit: I'd move this test under `test_timestamp_to_nanos` so related
`timestamp_to_nanos` tests stay close together.
##########
pyiceberg/utils/datetime.py:
##########
@@ -140,7 +140,7 @@ def timestamptz_to_nanos(timestamptz_str: str) -> int:
ms_str = match.group(2) if match.group(2) else ""
timestamptz_str_without_ns_str = match.group(1) + ms_str +
match.group(4)
return
datetime_to_nanos(datetime.fromisoformat(timestamptz_str_without_ns_str)) +
int(ns_str)
- if ISO_TIMESTAMPTZ_NANO.fullmatch(timestamptz_str):
+ if ISO_TIMESTAMP_NANO.fullmatch(timestamptz_str):
# When we can match a timestamp without a zone, we can give a more
specific error
raise ValueError(f"Missing zone offset: {timestamptz_str} (must be
ISO-8601)")
raise ValueError(f"Invalid timestamp with zone: {timestamptz_str} (must be
ISO-8601)")
Review Comment:
nit: We could add test cases for `Invalid timestamp with zone` in this
method and `Invalid timestamp without zone` in `timestamp_to_nanos` as a
follow-up.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]