diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index da4077165add2..be11732d7b3a2 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1207,13 +1207,20 @@ def set_atom(self, block, existing_col, min_itemsize, nan_rep, **kwargs): self.values = list(block.items) dtype = block.dtype.name - inferred_type = lib.infer_dtype(block.values.ravel()) + rvalues = block.values.ravel() + inferred_type = lib.infer_dtype(rvalues) if inferred_type == 'datetime64': self.set_atom_datetime64(block) elif inferred_type == 'date': raise TypeError( "[date] is not implemented as a table column") + elif inferred_type == 'datetime': + if getattr(rvalues[0],'tzinfo',None) is not None: + raise TypeError( + "timezone support on datetimes is not yet implemented as a table column") + raise TypeError( + "[datetime] is not implemented as a table column") elif inferred_type == 'unicode': raise TypeError( "[unicode] is not implemented as a table column") @@ -2080,8 +2087,18 @@ def validate(self, other): (other.table_type, self.table_type)) for c in ['index_axes','non_index_axes','values_axes']: - if getattr(self,c,None) != getattr(other,c,None): - raise ValueError("invalid combinate of [%s] on appending data [%s] vs current table [%s]" % (c,getattr(self,c,None),getattr(other,c,None))) + sv = getattr(self,c,None) + ov = getattr(other,c,None) + if sv != ov: + + # show the error for the specific axes + for i, sax in enumerate(sv): + oax = ov[i] + if sax != oax: + raise ValueError("invalid combinate of [%s] on appending data [%s] vs current table [%s]" % (c,sax,oax)) + + # should never get here + raise Exception("invalid combinate of [%s] on appending data [%s] vs current table [%s]" % (c,sv,ov)) @property def nrows_expected(self): diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index 598812373538c..75fe0eefe771e 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -1150,15 +1150,19 @@ def test_table_values_dtypes_roundtrip(self): df1['float322'] = 1. df1['float322'] = df1['float322'].astype('float32') df1['bool'] = df1['float32'] > 0 + df1['time1'] = Timestamp('20130101') + df1['time2'] = Timestamp('20130102') store.append('df_mixed_dtypes1', df1) result = store.select('df_mixed_dtypes1').get_dtype_counts() expected = Series({ 'float32' : 2, 'float64' : 1,'int32' : 1, 'bool' : 1, - 'int16' : 1, 'int8' : 1, 'int64' : 1, 'object' : 1 }) + 'int16' : 1, 'int8' : 1, 'int64' : 1, 'object' : 1, + 'datetime64[ns]' : 2}) result.sort() expected.sort() tm.assert_series_equal(result,expected) + def test_table_mixed_dtypes(self): # frame @@ -1231,6 +1235,17 @@ def test_unimplemented_dtypes_table_columns(self): # this fails because we have a date in the object block...... self.assertRaises(TypeError, store.append, 'df_unimplemented', df) + def test_table_append_with_timezones(self): + # not implemented yet + + with ensure_clean(self.path) as store: + + # check with mixed dtypes + df = DataFrame(dict(A = Timestamp('20130102',tz='US/Eastern')),index=range(5)) + + # timezones not yet supported + self.assertRaises(TypeError, store.append, 'df_tz', df) + def test_remove(self): with ensure_clean(self.path) as store: