Skip to content

Commit

Permalink
added test for trying to write to legacy_tables (which now fails corr…
Browse files Browse the repository at this point in the history
…ectly)
  • Loading branch information
jreback authored and wesm committed Dec 1, 2012
1 parent 35f37fa commit ff21355
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MANIFEST
*.cpp
*.so
*.pyd
*.h5
pandas/version.py
doc/source/generated
doc/source/_static
Expand Down
34 changes: 18 additions & 16 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,9 @@ class LegacyTable(Table):
_indexables = [Col(name = 'index'),Col(name = 'column', index_kind = 'columns_kind'), DataCol(name = 'fields', cname = 'values', kind_attr = 'fields') ]
table_type = 'legacy'

def write(self, **kwargs):
raise Exception("write operations are not allowed on legacy tables!")

def read(self, where=None):
""" we have 2 indexable columns, with an arbitrary number of data axes """

Expand Down Expand Up @@ -1429,6 +1432,21 @@ def read(self, where=None):

return wp

class LegacyFrameTable(LegacyTable):
""" support the legacy frame table """
table_type = 'legacy_frame'
def read(self, *args, **kwargs):
return super(LegacyFrameTable, self).read(*args, **kwargs)['value']

class LegacyPanelTable(LegacyTable):
""" support the legacy panel table """
table_type = 'legacy_panel'

class AppendableTable(LegacyTable):
""" suppor the new appendable table formats """
_indexables = None
table_type = 'appendable'

def write(self, axes_to_index, obj, append=False, compression=None,
complevel=None, min_itemsize = None, **kwargs):

Expand Down Expand Up @@ -1537,22 +1555,6 @@ def delete(self, where = None):
# return the number of rows removed
return ln


class LegacyFrameTable(LegacyTable):
""" support the legacy frame table """
table_type = 'legacy_frame'
def read(self, *args, **kwargs):
return super(LegacyFrameTable, self).read(*args, **kwargs)['value']

class LegacyPanelTable(LegacyTable):
""" support the legacy panel table """
table_type = 'legacy_panel'

class AppendableTable(LegacyTable):
""" suppor the new appendable table formats """
_indexables = None
table_type = 'appendable'

class AppendableFrameTable(AppendableTable):
""" suppor the new appendable table formats """
table_type = 'appendable_frame'
Expand Down
13 changes: 13 additions & 0 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,19 @@ def test_legacy_table_read(self):
store.select('wp1')
store.close()

def test_legacy_table_write(self):
# legacy table types
pth = curpath()
df = tm.makeDataFrame()
wp = tm.makePanel()

store = HDFStore(os.path.join(pth, 'legacy_table.h5'), 'a')

self.assertRaises(Exception, store.append, 'df1', df)
self.assertRaises(Exception, store.append, 'wp1', wp)

store.close()

def test_store_datetime_fractional_secs(self):
dt = datetime(2012, 1, 2, 3, 4, 5, 123456)
series = Series([0], [dt])
Expand Down

0 comments on commit ff21355

Please sign in to comment.