"Already tz-aware" error when reading h5 file using pandas, python 3 (but not 2) -
i have h5 store named weather.h5
. default python environment 3.5.2. when try read store typeerror: tz-aware, use tz_convert convert
.
i've tried both pd.read_hdf('weather.h5','weather_history')
, pd.io.pytables.hdfstore('weather.h5')['weather_history]
, error no matter what.
i can open h5 in python 2.7 environment. bug in python 3 / pandas?
i have same issue. i'm using anaconda python: 3.4.5 , 2.7.3. both using pandas 0.18.1.
here reproducible example:
generate.py (to executed python2):
import pandas pd pandas import hdfstore index = pd.datetimeindex(['2017-06-20 06:00:06.984630-05:00', '2017-06-20 06:03:01.042616-05:00'], dtype='datetime64[ns, cst6cdt]', freq=none) p1 = [0, 1] p2 = [0, 2] # saving of these dataframes cause issues df1 = pd.dataframe({"p1":p1, "p2":p2}, index=index) df2 = pd.dataframe({"p1":p1, "p2":p2, "i":index}) store = hdfstore("./test_issue.h5") store['df'] = df1 #store['df'] = df2 store.close()
read_issue.py:
import pandas pd pandas import hdfstore store = hdfstore("./test_issue.h5", mode="r") df = store['/df'] store.close() print(df)
running read_issue.py in python2 has no issues , produces output:
p1 p2
2017-06-20 11:00:06.984630-05:00 0 0 2017-06-20 11:03:01.042616-05:00 1 2
but running in python3 produces error traceback:
traceback (most recent call last): file "read_issue.py", line 5, in df = store['df'] file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 417, in getitem return self.get(key) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 634, in return self._read_group(group) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 1272, in _read_group return s.read(**kwargs) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 2779, in read ax = self.read_index('axis%d' % i) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 2367, in read_index _, index = self.read_index_node(getattr(self.group, key)) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 2492, in read_index_node _unconvert_index(data, kind, encoding=self.encoding), **kwargs) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/indexes/base.py", line 153, in new result = datetimeindex(data, copy=copy, name=name, **kwargs) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/util/decorators.py", line 91, in wrapper return func(*args, **kwargs) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/tseries/index.py", line 321, in new raise typeerror("already tz-aware, use tz_convert " typeerror: tz-aware, use tz_convert convert. closing remaining open files:./test_issue.h5...done
so, there issue indices. however, if save df2 in generate.py (datetime column, not index), python3 in read_issue.py produces different error:
traceback (most recent call last): file "read_issue.py", line 5, in df = store['/df'] file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 417, in getitem return self.get(key) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 634, in return self._read_group(group) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 1272, in _read_group return s.read(**kwargs) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 2788, in read placement=items.get_indexer(blk_items)) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/core/internals.py", line 2518, in make_block return klass(values, ndim=ndim, fastpath=fastpath, placement=placement) file "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/core/internals.py", line 90, in init len(self.mgr_locs))) valueerror: wrong number of items passed 2, placement implies 1 closing remaining open files:./test_issue.h5...done
also, if execute generate_issue.py in python3 (saving either df1 or df2), there no problem executing read_issue.py in either python3 or python2
Comments
Post a Comment