Skip to content

TIMESTAMP WITH TIME ZONE values with a numeric UTC offset come back naive #854

Description

@aminghadersohi

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions