Skip to content

Add support for timestamps with timezone#649

Merged
sfc-gh-jcieslak merged 4 commits intomainfrom
jcieslak/support-for-timestamps-with-timezones
Feb 25, 2026
Merged

Add support for timestamps with timezone#649
sfc-gh-jcieslak merged 4 commits intomainfrom
jcieslak/support-for-timestamps-with-timezones

Conversation

@sfc-gh-jcieslak
Copy link
Member

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-219884: Pandas datetime with timezone converts to timestamp_ntz in snowflake #199

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding new credentials
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    Previously, the dialect didn't respect the timezone settings on datetime and timezone SQLAlchemy types and produced timestamp types without a timezone. With the provided change, whenever the timezone option is set for either type, the timestamp with timezone will be used.

@sfc-gh-jcieslak sfc-gh-jcieslak requested a review from a team as a code owner February 12, 2026 15:06
@sfc-gh-jcieslak sfc-gh-jcieslak marked this pull request as draft February 16, 2026 16:10
@sfc-gh-jcieslak sfc-gh-jcieslak force-pushed the jcieslak/support-for-timestamps-with-timezones branch from 7a6c074 to 8e9b697 Compare February 18, 2026 12:32
@sfc-gh-jcieslak sfc-gh-jcieslak marked this pull request as ready for review February 18, 2026 12:33
Comment on lines +38 to +40
def test_custom_datetime_preserves_timezone_flag(self):
custom_datetime = DateTime(timezone=True).adapt(_CUSTOM_DateTime)
assert getattr(custom_datetime, "timezone", None) is True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dialect's colspecs maps DateTime -> _CUSTOM_DateTime:
snowdialect.py:60-65

colspecs = {    
    Date: _CUSTOM_Date,    
    DateTime: _CUSTOM_DateTime,    
    Time: _CUSTOM_Time,    
    Float: _CUSTOM_Float,
}

When SQLAlchemy adapts DateTime(timezone=True) to _CUSTOM_DateTime, it calls .adapt(_CUSTOM_DateTime). The test test_custom_datetime_preserves_timezone_flag checks this, but _CUSTOM_DateTime inherits from both SnowflakeType and sqltypes.DateTime — it does not define __init__ to accept/forward the timezone keyword. The base DateTime.__init__ sets self.timezone, so .adapt() copies it via __dict__. It would be safer and more explicit if _CUSTOM_DateTime accepted timezone in its constructor:

class _CUSTOM_DateTime(SnowflakeType, sqltypes.DateTime):    
    def __init__(self, timezone=False):        
        super().__init__(timezone=timezone)    
        ...

This makes the intent explicit and protects against future SQLAlchemy changes to the adapt mechanism.

@sfc-gh-jcieslak sfc-gh-jcieslak merged commit f1d79ed into main Feb 25, 2026
55 of 64 checks passed
@sfc-gh-jcieslak sfc-gh-jcieslak deleted the jcieslak/support-for-timestamps-with-timezones branch February 25, 2026 12:25
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SNOW-219884: Pandas datetime with timezone converts to timestamp_ntz in snowflake

2 participants