Problem
DefaultTypeConverter resolves the zone of a timestamp with time zone value with dateutil.tz.gettz. Athena renders a numeric offset as +05:30 / -08:00, for which gettz returns None, so the cursor returns a naive wall-clock datetime and the instant is lost. Zone names (America/New_York, UTC) work.
Expected: an aware datetime with a fixed +05:30 offset.
Reproduction
from pyathena.converter import DefaultTypeConverter
DefaultTypeConverter().convert('timestamp with time zone', '2024-02-29 23:59:58.123 +05:30')
# datetime.datetime(2024, 2, 29, 23, 59, 58, 123000) -> tzinfo is None
Live: SELECT TIMESTAMP '2024-02-29 23:59:58.123456 +05:30' through the REST cursor returns a naive value.
Environment
PyAthena 3.35.4 and master (c01c56f), Python 3.11, SQLAlchemy 2.0.52, Athena engine version 3.
Proposed fix (optional)
Parse a trailing [+-]HH:MM token into datetime.timezone(timedelta(...)) and fall back to the zone-name lookup otherwise. Happy to send a PR with unit tests if the approach is agreed; I can validate against my own Athena workgroup.
Problem
DefaultTypeConverterresolves the zone of atimestamp with time zonevalue withdateutil.tz.gettz. Athena renders a numeric offset as+05:30/-08:00, for whichgettzreturnsNone, so the cursor returns a naive wall-clock datetime and the instant is lost. Zone names (America/New_York,UTC) work.Expected: an aware datetime with a fixed
+05:30offset.Reproduction
Live:
SELECT TIMESTAMP '2024-02-29 23:59:58.123456 +05:30'through the REST cursor returns a naive value.Environment
PyAthena 3.35.4 and master (c01c56f), Python 3.11, SQLAlchemy 2.0.52, Athena engine version 3.
Proposed fix (optional)
Parse a trailing
[+-]HH:MMtoken intodatetime.timezone(timedelta(...))and fall back to the zone-name lookup otherwise. Happy to send a PR with unit tests if the approach is agreed; I can validate against my own Athena workgroup.