I have an h5 store named weather.h5. My default Python environment is 3.5.2. When I try to read this store I get TypeError: Already tz-aware, use tz_convert to convert.

I've tried both pd.read_hdf('weather.h5','weather_history'] and pd.io.pytables.HDFStore('weather.h5')['weather_history'], but I get the error no matter what.

I can open the h5 in a Python 2.7 environment, so I'm assuming that this is a bug relating to the Python 3.5 install of pandas.

Traceback for pd.read_hdf('weather.h5','weather_history']

Traceback (most recent call last)
<ipython-input-21-716ccba8a093> in <module>()
----> 1 pd.read_hdf('weather.h5', 'weather_history')

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in read_hdf(path_or_buf, key, **kwargs)
    328                                  'multiple datasets.')
    329             key = keys[0]
--> 330         return store.select(key, auto_close=auto_close, **kwargs)
    331     except:
    332         # if there is an error, close the store

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in select(self, key, where, start, stop, columns, iterator, chunksize, auto_close, **kwargs)
    678                            chunksize=chunksize, auto_close=auto_close)
    679 
--> 680         return it.get_result()
    681 
    682     def select_as_coordinates(

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in get_result(self, coordinates)
   1362 
   1363         # directly return the result
-> 1364         results = self.func(self.start, self.stop, where)
   1365         self.close()
   1366         return results

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in func(_start, _stop, _where)
    671             return s.read(start=_start, stop=_stop,
    672                           where=_where,
--> 673                           columns=columns, **kwargs)
    674 
    675         # create the iterator

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in read(self, **kwargs)
   2777         axes = []
   2778         for i in range(self.ndim):
-> 2779             ax = self.read_index('axis%d' % i)
   2780             axes.append(ax)
   2781 

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in read_index(self, key)
   2365             return self.read_sparse_intindex(key)
   2366         elif variety == u('regular'):
-> 2367             _, index = self.read_index_node(getattr(self.group, key))
   2368             return index
   2369         else:  # pragma: no cover

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in read_index_node(self, node)
   2490         else:
   2491             index = factory(
-> 2492                 _unconvert_index(data, kind, encoding=self.encoding), **kwargs)
   2493 
   2494         index.name = name

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/indexes/base.py in __new__(cls, data, dtype, copy, name, fastpath, tupleize_cols, **kwargs)
    151                     is_datetimetz(data)):
    152                 from pandas.tseries.index import DatetimeIndex
--> 153                 result = DatetimeIndex(data, copy=copy, name=name, **kwargs)
    154                 if dtype is not None and _o_dtype == dtype:
    155                     return Index(result.to_pydatetime(), dtype=_o_dtype)

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/util/decorators.py in wrapper(*args, **kwargs)
     89                 else:
     90                     kwargs[new_arg_name] = new_arg_value
---> 91             return func(*args, **kwargs)
     92         return wrapper
     93     return _deprecate_kwarg

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/tseries/index.py in __new__(cls, data, freq, start, end, periods, copy, name, tz, verify_integrity, normalize, closed, ambiguous, dtype, **kwargs)
    319                     # the tz's must match
    320                     if str(tz) != str(data.tz):
--> 321                         raise TypeError("Already tz-aware, use tz_convert "
    322                                         "to convert.")
    323 

TypeError: Already tz-aware, use tz_convert to convert.

Traceback for pd.io.pytables.HDFStore('weather.h5')['weather_history']

Traceback (most recent call last)
<ipython-input-25-8aaea36ce932> in <module>()
----> 1 pd.io.pytables.HDFStore('weather.h5')['weather_history']

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in __getitem__(self, key)
    415 
    416     def __getitem__(self, key):
--> 417         return self.get(key)
    418 
    419     def __setitem__(self, key, value):

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in get(self, key)
    632         if group is None:
    633             raise KeyError('No object named %s in the file' % key)
--> 634         return self._read_group(group)
    635 
    636     def select(self, key, where=None, start=None, stop=None, columns=None,

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in _read_group(self, group, **kwargs)
   1270         s = self._create_storer(group)
   1271         s.infer_axes()
-> 1272         return s.read(**kwargs)
   1273 
   1274 

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in read(self, **kwargs)
   2777         axes = []
   2778         for i in range(self.ndim):
-> 2779             ax = self.read_index('axis%d' % i)
   2780             axes.append(ax)
   2781 

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in read_index(self, key)
   2365             return self.read_sparse_intindex(key)
   2366         elif variety == u('regular'):
-> 2367             _, index = self.read_index_node(getattr(self.group, key))
   2368             return index
   2369         else:  # pragma: no cover

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/io/pytables.py in read_index_node(self, node)
   2490         else:
   2491             index = factory(
-> 2492                 _unconvert_index(data, kind, encoding=self.encoding), **kwargs)
   2493 
   2494         index.name = name

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/indexes/base.py in __new__(cls, data, dtype, copy, name, fastpath, tupleize_cols, **kwargs)
    151                     is_datetimetz(data)):
    152                 from pandas.tseries.index import DatetimeIndex
--> 153                 result = DatetimeIndex(data, copy=copy, name=name, **kwargs)
    154                 if dtype is not None and _o_dtype == dtype:
    155                     return Index(result.to_pydatetime(), dtype=_o_dtype)

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/util/decorators.py in wrapper(*args, **kwargs)
     89                 else:
     90                     kwargs[new_arg_name] = new_arg_value
---> 91             return func(*args, **kwargs)
     92         return wrapper
     93     return _deprecate_kwarg

/Users/jkelleher/anaconda/lib/python3.5/site-packages/pandas/tseries/index.py in __new__(cls, data, freq, start, end, periods, copy, name, tz, verify_integrity, normalize, closed, ambiguous, dtype, **kwargs)
    319                     # the tz's must match
    320                     if str(tz) != str(data.tz):
--> 321                         raise TypeError("Already tz-aware, use tz_convert "
    322                                         "to convert.")
    323 

TypeError: Already tz-aware, use tz_convert to convert.

Output of pd.show_versions()

## INSTALLED VERSIONS commit: None python: 3.5.2.final.0 python-bits: 64 OS: Darwin OS-release: 15.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 pandas: 0.18.1 nose: 1.3.7 pip: 8.1.2 setuptools: 27.2.0 Cython: 0.24.1 numpy: 1.11.1 scipy: 0.18.1 statsmodels: 0.6.1 xarray: None IPython: 5.1.0 sphinx: 1.4.1 patsy: 0.4.1 dateutil: 2.5.3 pytz: 2016.6.1 blosc: None bottleneck: 1.1.0 tables: 3.2.2 numexpr: 2.6.0 matplotlib: 1.5.3 openpyxl: 2.3.2 xlrd: 1.0.0 xlwt: 1.1.2 xlsxwriter: 0.9.2 lxml: 3.6.0 bs4: 4.4.1 html5lib: None httplib2: None apiclient: None sqlalchemy: 1.0.13 pymysql: None psycopg2: None jinja2: 2.8 boto: 2.40.0 pandas_datareader: None

Comment From: jameskelleher

I'm reporting this issue as I posted a question about it to Stack Overflow and received no response http://stackoverflow.com/questions/39640860/already-tz-aware-error-when-reading-h5-file-using-pandas-python-3-but-not-2

If there's a solution I'll close both posts

Comment From: jreback

you would have to show a reproducible example. e.g. create a frame with appropriate dtype in py2, then read in py3. Pls show the versions of pandas on both. The version must be >= of the version in py2. (note that you cannot go backwards, from py3 -> py2)

Comment From: jorisvandenbossche

@jameskelleher I am going to close this issue, but happy to reopen it if you can provide a reproducible example.