Skip to content

Commit 54349d1

Browse files
committed
Merge pull request #4957 from cpcloud/hdfstore-append-error-fix
BUG: fix incorrect TypeError raise
2 parents cef13db + c9847ad commit 54349d1

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ Bug Fixes
453453
- Fixed a bug with setting invalid or out-of-range values in indexing
454454
enlargement scenarios (:issue:`4940`)
455455
- Tests for fillna on empty Series (:issue:`4346`), thanks @immerrr
456+
- Fixed a bug where ``ValueError`` wasn't correctly raised when column names
457+
weren't strings (:issue:`4956`)
456458

457459
pandas 0.12.0
458460
-------------

pandas/io/pytables.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,9 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None,
30333033
new_blocks.append(b)
30343034
except:
30353035
raise ValueError(
3036-
"cannot match existing table structure for [%s] on appending data" % ','.join(items))
3036+
"cannot match existing table structure for [%s] on "
3037+
"appending data" % ','.join(com.pprint_thing(item) for
3038+
item in items))
30373039
blocks = new_blocks
30383040

30393041
# add my values

pandas/io/tests/test_pytables.py

+15
Original file line numberDiff line numberDiff line change
@@ -3696,6 +3696,21 @@ def test_store_datetime_mixed(self):
36963696

36973697
# self.assertRaises(Exception, store.put, 'foo', df, format='table')
36983698

3699+
def test_append_with_diff_col_name_types_raises_value_error(self):
3700+
df = DataFrame(np.random.randn(10, 1))
3701+
df2 = DataFrame({'a': np.random.randn(10)})
3702+
df3 = DataFrame({(1, 2): np.random.randn(10)})
3703+
df4 = DataFrame({('1', 2): np.random.randn(10)})
3704+
df5 = DataFrame({('1', 2, object): np.random.randn(10)})
3705+
3706+
with ensure_clean('__%s__.h5' % tm.rands(20)) as store:
3707+
name = 'df_%s' % tm.rands(10)
3708+
store.append(name, df)
3709+
3710+
for d in (df2, df3, df4, df5):
3711+
with tm.assertRaises(ValueError):
3712+
store.append(name, d)
3713+
36993714

37003715
def _test_sort(obj):
37013716
if isinstance(obj, DataFrame):

0 commit comments

Comments
 (0)