Rahul-cs50 opened a new pull request, #4220:
URL: https://github.com/apache/iceberg-python/pull/4220

   Closes #4182
   
   # Rationale for this change
   
   `expire_snapshots().older_than(dt)` converts the cutoff with 
`datetime_to_millis`, which reads a naive datetime as UTC. The docs call it as 
`older_than(datetime.now() - timedelta(days=3))`, and `datetime.now()` is a 
naive local time, so east of UTC the cutoff lands later than asked (in Tokyo, 
`datetime.now() - timedelta(hours=1)` expires snapshots that are seconds old) 
and west of UTC it lands earlier.
   
   `older_than()` now reads a naive datetime as local time, as 
`datetime.timestamp()` does, by calling `astimezone()` on it before the 
conversion. An aware datetime is handled as before. `datetime_to_millis` itself 
is unchanged, since a naive value there means UTC for timestamp columns.
   
   ## Are these changes tested?
   
   Yes. `test_expire_snapshots_older_than_reads_naive_datetime_as_local_time` 
in `tests/table/test_expire_snapshots.py` sets `TZ` to `Asia/Tokyo` and checks 
that a naive cutoff one minute before a snapshot keeps it and one minute after 
expires it. It fails on `main` and passes with this change (it is skipped where 
`time.tzset` is unavailable). The issue's script now keeps all three snapshots 
under `Asia/Tokyo`, `America/Los_Angeles` and `UTC`. `tests/table` and 
`tests/utils`: 768 passed. `ruff check` and `ruff format --check` are clean.
   
   ## Are there any user-facing changes?
   
   `older_than()` with a naive datetime now uses the local time zone instead of 
UTC. Callers who passed naive UTC datetimes on purpose should pass an aware one 
(`datetime.now(timezone.utc)`).
   


-- 
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]

Reply via email to