Skip to content

TST: added testing and error messages for passing datetimes with timezones #3405

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

Merged
merged 1 commit into from
Apr 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down
17 changes: 16 additions & 1 deletion pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down