-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Reading from parquet throws UnknownTimeZoneError using timezone-aware date in index #35997
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
Comments
Thanks @alippai, looks like something may have changed for 1.1.0. Previously (1.0.5 and 1.0.0 at least) writing with the pyarrow engine would actually raise an ArrowInvalid exception, whereas now you can write but can't read. If you have the dependencies installed then an apparent workaround is to write using fastparquet instead: In [1]: import pandas as pd
...: from datetime import datetime, timezone
...:
...: print(pd.__version__)
...:
...: idx = 5 * [datetime.now(timezone.utc)]
...: df = pd.DataFrame(index=idx)
...: df.to_parquet("out.parquet", engine="fastparquet")
...: pd.read_parquet("out.parquet", engine="pyarrow")
...:
1.1.1
Out[1]:
Empty DataFrame
Columns: []
Index: [2020-08-31 00:50:41.828864+00:00, 2020-08-31 00:50:41.828864+00:00, 2020-08-31 00:50:41.828864+00:00, 2020-08-31 00:50:41.828864+00:00, 2020-08-31 00:50:41.828864+00:00] cc @jorisvandenbossche who may know what's happening |
Likely relevant: commit be9ee6d
doc/source/whatsnew/v1.1.0.rst | 4 +++- |
Note that pyarrow |
I've added a test, maybe it helps: https://travis-ci.org/github/pandas-dev/pandas/jobs/722666704 |
One more interesting thing. Using import pandas as pd
from datetime import datetime, timezone
import pyarrow.parquet as pq
from pytz import timezone as pytztimezone
normal_date = datetime(2011, 8, 15, 8, 15, 12, 0, timezone.utc)
pytz_date = datetime(2011, 8, 15, 8, 15, 12, 0, pytztimezone('UTC'))
print(f'Normal date: {normal_date.tzinfo}')
print(f'pytz: {pytz_date.tzinfo}')
print(f'Normal date: {normal_date.tzname()}')
print(f'pytz: {pytz_date.tzname()}')
pd.DataFrame(index=[pytz_date]).to_parquet('pytz.parquet')
pd.DataFrame(index=[normal_date]).to_parquet('normal.parquet')
print(pq.read_table('pytz.parquet').schema.metadata)
print(pq.read_table('normal.parquet').schema.metadata)
print(pq.read_table('pytz.parquet').to_pandas())
print(pq.read_table('normal.parquet').to_pandas()) Output:
|
Fastparquet fails writing date with timezone but no timezone name: import pandas as pd
from datetime import datetime, timezone
idx = [datetime.strptime('2019-01-04T16:41:24+0200', "%Y-%m-%dT%H:%M:%S%z")]
df = pd.DataFrame(index=idx)
df.to_parquet("out.parquet", engine="fastparquet") Raises:
|
@jreback The PR is ready to review now |
@alippai will take a look tomorrow (will also look into if this is not actually something we should long term solve in pyarrow, but need to better understand the actual first) |
@jorisvandenbossche regarding pyarrow #35997 (comment) this behavior is the most interesting. With two same / similar timezones pyarrow serializes the metadata differently. This is something you want to change eventually. The PR doesn't fix/improve the serialization, but it helps reading back the already written metadata. |
@dsaxton that's actually because of the commit you linked to (#31652). If you pass So it seems this bug is already present some time. Also with pyarrow 0.17 I get a similar error for roundtripping a pandas dataframe to pyarrow table with tz-aware index. @alippai the issue is indeed with how pyarrow stores the timezone in the schema metadata. For pytz it uses I am still wondering why it doesn't fail for normal columns, though. And pyarrow should probably also recognize |
So the reason is that for normal columns pyarrow first converted the string "+01:00" to a python timezone with an internal utility ( I think we should still recognize Independently from my fix in arrow, I think we can certainly still try to support "+01:00"-like strings in pandas as well (-> #36004) |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
Problem description
The bug above happens with pandas 1.1.1 and pyarrow 1.0.1.
The timezone-aware date in the index should survive the parquet round trip.
If
date
is not index, or when I add parameterignore_metadata=True
to thepyarrow.Table.to_pandas()
it works (butdate
won't be an index automatically)Expected Output
A correct DataFrame
Output of
pd.show_versions()
pandas : 1.1.1
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.2
setuptools : 49.6.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: