Skip to content

Commit ff21355

Browse files
jrebackwesm
authored andcommitted
added test for trying to write to legacy_tables (which now fails correctly)
1 parent 35f37fa commit ff21355

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ MANIFEST
1111
*.cpp
1212
*.so
1313
*.pyd
14+
*.h5
1415
pandas/version.py
1516
doc/source/generated
1617
doc/source/_static

pandas/io/pytables.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,9 @@ class LegacyTable(Table):
13551355
_indexables = [Col(name = 'index'),Col(name = 'column', index_kind = 'columns_kind'), DataCol(name = 'fields', cname = 'values', kind_attr = 'fields') ]
13561356
table_type = 'legacy'
13571357

1358+
def write(self, **kwargs):
1359+
raise Exception("write operations are not allowed on legacy tables!")
1360+
13581361
def read(self, where=None):
13591362
""" we have 2 indexable columns, with an arbitrary number of data axes """
13601363

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

14301433
return wp
14311434

1435+
class LegacyFrameTable(LegacyTable):
1436+
""" support the legacy frame table """
1437+
table_type = 'legacy_frame'
1438+
def read(self, *args, **kwargs):
1439+
return super(LegacyFrameTable, self).read(*args, **kwargs)['value']
1440+
1441+
class LegacyPanelTable(LegacyTable):
1442+
""" support the legacy panel table """
1443+
table_type = 'legacy_panel'
1444+
1445+
class AppendableTable(LegacyTable):
1446+
""" suppor the new appendable table formats """
1447+
_indexables = None
1448+
table_type = 'appendable'
1449+
14321450
def write(self, axes_to_index, obj, append=False, compression=None,
14331451
complevel=None, min_itemsize = None, **kwargs):
14341452

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

1540-
1541-
class LegacyFrameTable(LegacyTable):
1542-
""" support the legacy frame table """
1543-
table_type = 'legacy_frame'
1544-
def read(self, *args, **kwargs):
1545-
return super(LegacyFrameTable, self).read(*args, **kwargs)['value']
1546-
1547-
class LegacyPanelTable(LegacyTable):
1548-
""" support the legacy panel table """
1549-
table_type = 'legacy_panel'
1550-
1551-
class AppendableTable(LegacyTable):
1552-
""" suppor the new appendable table formats """
1553-
_indexables = None
1554-
table_type = 'appendable'
1555-
15561558
class AppendableFrameTable(AppendableTable):
15571559
""" suppor the new appendable table formats """
15581560
table_type = 'appendable_frame'

pandas/io/tests/test_pytables.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,19 @@ def test_legacy_table_read(self):
898898
store.select('wp1')
899899
store.close()
900900

901+
def test_legacy_table_write(self):
902+
# legacy table types
903+
pth = curpath()
904+
df = tm.makeDataFrame()
905+
wp = tm.makePanel()
906+
907+
store = HDFStore(os.path.join(pth, 'legacy_table.h5'), 'a')
908+
909+
self.assertRaises(Exception, store.append, 'df1', df)
910+
self.assertRaises(Exception, store.append, 'wp1', wp)
911+
912+
store.close()
913+
901914
def test_store_datetime_fractional_secs(self):
902915
dt = datetime(2012, 1, 2, 3, 4, 5, 123456)
903916
series = Series([0], [dt])

0 commit comments

Comments
 (0)