Skip to content

Commit 000a159

Browse files
committed
fix duckdb#6466 convert datetime with tzinfo to a timestamptz instead of timestamp
1 parent 846a32b commit 000a159

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tools/pythonpkg/src/python_objects.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ Value PyDateTime::ToDuckValue() {
251251
// Need to subtract the UTC offset, so we invert the interval
252252
utc_offset = Interval::Invert(utc_offset);
253253
timestamp = Interval::Add(timestamp, utc_offset);
254+
return Value::TIMESTAMPTZ(timestamp);
254255
}
255256
return Value::TIMESTAMP(timestamp);
256257
}

tools/pythonpkg/tests/fast/pandas/test_datetime_time.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,19 @@ def test_pandas_datetime_overflow(self):
6969

7070
with pytest.raises(duckdb.ConversionException):
7171
res = duckdb_con.execute("select * from test").df()
72+
73+
def test_timezone_datetime(self):
74+
module = pytest.importorskip("datetime")
75+
timezone = module.timezone
76+
datetime = module.datetime
77+
78+
con = duckdb.connect()
79+
80+
dt = datetime.now(timezone.utc).replace(microsecond=0)
81+
82+
original = dt
83+
stringified = str(dt)
84+
85+
original_res = con.execute('select ?::TIMESTAMPTZ', [original]).fetchone()
86+
stringified_res = con.execute('select ?::TIMESTAMPTZ', [stringified]).fetchone()
87+
assert original_res == stringified_res

0 commit comments

Comments
 (0)