Add support for timestamps with timezone#649
Merged
sfc-gh-jcieslak merged 4 commits intomainfrom Feb 25, 2026
Merged
Conversation
7a6c074 to
8e9b697
Compare
# Conflicts: # DESCRIPTION.md
tests/test_timestamp.py
Outdated
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 |
Collaborator
There was a problem hiding this comment.
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-mraba
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please answer these questions before submitting your pull requests. Thanks!
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_ntzin snowflake #199Fill out the following pre-review checklist:
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.