Skip to content

Commit e76258f

Browse files
committed
ER: HDFStore raising an invalid TypeError rather than ValueError when appending with
different block ordering (GH4096) related
1 parent 1412f66 commit e76258f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/source/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ pandas 0.13
4444

4545
**Bug Fixes**
4646

47+
- ``HDFStore`` raising an invalid ``TypeError`` rather than ``ValueError`` when appending
48+
with a different block ordering (:issue:`4096`)
49+
4750
pandas 0.12
4851
===========
4952

pandas/io/pytables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None, data_columns=None,
26722672
b = by_items.pop(items)
26732673
new_blocks.append(b)
26742674
except:
2675-
raise ValueError("cannot match existing table structure for [%s] on appending data" % items)
2675+
raise ValueError("cannot match existing table structure for [%s] on appending data" % ','.join(items))
26762676
blocks = new_blocks
26772677

26782678
# add my values

pandas/io/tests/test_pytables.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,21 @@ def test_append_with_different_block_ordering(self):
620620

621621
store.append('df',df)
622622

623+
# test a different ordering but with more fields (like invalid combinate)
624+
with ensure_clean(self.path) as store:
625+
626+
df = DataFrame(np.random.randn(10,2),columns=list('AB'), dtype='float64')
627+
df['int64'] = Series([1]*len(df),dtype='int64')
628+
df['int16'] = Series([1]*len(df),dtype='int16')
629+
store.append('df',df)
630+
631+
# store additonal fields in different blocks
632+
df['int16_2'] = Series([1]*len(df),dtype='int16')
633+
self.assertRaises(ValueError, store.append, 'df', df)
634+
635+
# store multile additonal fields in different blocks
636+
df['float_3'] = Series([1.]*len(df),dtype='float64')
637+
self.assertRaises(ValueError, store.append, 'df', df)
623638

624639
def test_ndim_indexables(self):
625640
""" test using ndim tables in new ways"""

0 commit comments

Comments
 (0)