-
Notifications
You must be signed in to change notification settings - Fork 173
Closed
Labels
Milestone
Description
What would you like help with?
Starting with adbc-driver-postgresql v1.3.0, if I try to write my DF that has a timezone in it, the TZ is dropped.
I think this has to do with this:
https://arrow.apache.org/adbc/current/driver/postgresql.html#timestamp
Specifically this part:
When binding a timestamp value, the time zone (if present) is ignored. The value will be converted to microseconds and adjusted to the PostgreSQL epoch (2000-01-01) and so may overflow/underflow; an error will be returned if this would be the case.
However, I thought I was using the bulk ingestion feature through polars write_database method, which would preserve the TZ.
Quick code snippet:
from datetime import datetime
import adbc_driver_postgresql.dbapi
import polars as pl
df = pl.DataFrame({
"timestamp": pl.datetime_range(
start=datetime(2025, 5, 28, 8, 0),
end=datetime(2025, 5, 28, 12, 0),
interval="1h",
time_zone="UTC",
eager=True
)
})
table_name = "test_table"
uri = "postgresql://mac@localhost:5432/mac"
# Connect using ADBC
with adbc_driver_postgresql.dbapi.connect(uri) as conn:
with conn.cursor() as cur:
cur.execute(f"DROP TABLE IF EXISTS {table_name}")
conn.commit()
df.write_database(
table_name=table_name,
connection=uri,
engine="adbc",
if_table_exists="replace"
)
schema_query = f"""
SELECT data_type
FROM information_schema.columns
WHERE table_name = '{table_name}'
"""
df_schema = pl.read_database_uri(schema_query, uri, engine="adbc")
actual_data_type = df_schema["data_type"][0]
assert actual_data_type == "timestamp with time zone", actual_data_type
Running:
(adbc_test) mac@macbookpro adbc_test % uv pip install adbc-driver-postgresql==1.2.0
Resolved 4 packages in 15ms
Uninstalled 1 package in 1ms
Installed 1 package in 2ms
- adbc-driver-postgresql==1.3.0
+ adbc-driver-postgresql==1.2.0
(adbc_test) mac@macbookpro adbc_test % python test_script.py
(adbc_test) mac@macbookpro adbc_test % uv pip install adbc-driver-postgresql==1.3.0
Resolved 4 packages in 2ms
Uninstalled 1 package in 1ms
Installed 1 package in 2ms
- adbc-driver-postgresql==1.2.0
+ adbc-driver-postgresql==1.3.0
(adbc_test) mac@macbookpro adbc_test % python test_script.py
Traceback (most recent call last):
File "/Users/mac/adbc_test/test_script.py", line 41, in <module>
assert actual_data_type == "timestamp with time zone", actual_data_type
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: timestamp without time zone
skellys and nishi7409