-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL: error when reading postgres table with timezone #7139
Comments
I can't seem to mimic this error. I can mimic the aspect where a Fixing the underlying issue is actually really easy, you can just add So basically, I think this is working as intended, but if you can provide a full sample code or sample SQL dump that reproduces the error I'll take a look at it. |
FYI I have dug into this and have finally replicated it! Error message was a little misleading. The issue is that if you have a Simple gist to cause it: https://gist.github.com/danbirken/8f52541c453b386b8049 So this issue is very valid and I'll try to come up with a reasonable fix for it. I've discovered some related things while digging into this so maybe I can improve multiple things at once. |
@danbirken Thanks a lot for looking into this! I still have to look more detailed to what you have written, and see if I can reproduce it with the example you provided. But I can confirm that it was indeed a database table where the datetime column spanned both DST and non-DST periods. |
Yeah that is what I suspected, and given this will be a common issue it is a problem. I have a few ideas how to fix this i'll get some code out this week. |
Ignore this for a moment, after submitting I have had a change of heart on the best way to fix it. |
Alright, my change of heart is that if So I switched the logic to prevent this error from being raised to I also added in an additional feature, which is the keyword So with this change, the only real functionality change is that this error wont be triggered anymore. However, if a person uses the new I reconfigured |
(Resubmitting same change again because travis tests broke on an intermittent network error and I like that green check mark) |
Just run into this bug. Another minimal way to workaround this would be to make the date_time handling for "known" Datetime columns obey the |
Running into this bug a lot right with handling DST-enabled datetimes, any idea when this will be merged? |
There is no perfect solution to this bug which is why I suspect no solution has been merged. I've updated the pull request with my 4th and final proposal to fix this bug, and it is the simplest and I believe the correct fix. Up to the maintainers if they want to merge it, but this is a classic "perfect is the enemy of the good" bug and I don't like those. Rationale for this final proposal will be in the pull request. |
`read_sql_table()` will break if it reads a table with a `timestamp with time zone` column if individual rows within that column have different time zones. This is very common due to daylight savings time. Pandas right now does not have good support for a Series containing datetimes with different time zones (hence this bug). So this change simply converts a `timestamp with time zone` column into UTC during import, which pandas has great support for.
Until this is fixed an easy workaround might be to use read_sql_query and include AT TIME ZONE 'UTC' in your query. You can then localize to whatever timezone you need in pandas. |
`read_sql_table()` will break if it reads a table with a `timestamp with time zone` column if individual rows within that column have different time zones. This is very common due to daylight savings time. Pandas right now does not have good support for a Series containing datetimes with different time zones (hence this bug). So this change simply converts a `timestamp with time zone` column into UTC during import, which pandas has great support for.
Closed by #7364 |
Left over issue from #6292
I have a postgresql table with a column with type
timestamp with time zone
. Just reading this table (sql.read_sql_table("everyaware_by_passage", engine)
) did not work, because of a datetime column:ValueError: Tz-aware datetime.datetime cannot be converted to datetime64 unless utc=True
.I can import it with read_sql, and there the imported datetime column is of type datetime.datetime with
tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=120, name=None)
Full error traceback (and it seems an issue in pandas itself):
The text was updated successfully, but these errors were encountered: