@@ -421,14 +421,6 @@ def check_col(key, name, size):
421421 with pytest .raises (ValueError , match = msg ):
422422 store .append ("df_new" , df_new )
423423
424- # bigger NaN representation on next append
425- df_new = DataFrame ([[124 , "a" ], [346 , "b" ]])
426- store .append ("df_new2" , df_new )
427- df_new = DataFrame ([[124 , None ], [346 , "b" ]])
428- msg = "NaN representation is too large for existing column size"
429- with pytest .raises (ValueError , match = msg ):
430- store .append ("df_new2" , df_new )
431-
432424 # min_itemsize on Series index (GH 11412)
433425 df = DataFrame (
434426 {
@@ -835,7 +827,7 @@ def test_append_raise(setup_path):
835827 "because its data contents are not [string] "
836828 "but [datetime64[s]] object dtype"
837829 )
838- with pytest .raises (TypeError , match = msg ):
830+ with pytest .raises (ValueError , match = msg ):
839831 store .append ("df" , df )
840832
841833
@@ -1002,3 +994,29 @@ def test_append_to_multiple_min_itemsize(setup_path):
1002994 )
1003995 result = store .select_as_multiple (["index" , "nums" , "strs" ])
1004996 tm .assert_frame_equal (result , expected , check_index_type = True )
997+
998+
999+ def test_append_string_nan_rep (setup_path ):
1000+ # GH 16300
1001+ df = DataFrame ({"A" : "a" , "B" : "foo" }, index = np .arange (10 ))
1002+ df_nan = df .copy ()
1003+ df_nan .loc [0 :4 , :] = np .nan
1004+ msg = "NaN representation is too large for existing column size"
1005+
1006+ with ensure_clean_store (setup_path ) as store :
1007+ # string column too small
1008+ store .append ("sa" , df ["A" ])
1009+ with pytest .raises (ValueError , match = msg ):
1010+ store .append ("sa" , df_nan ["A" ])
1011+
1012+ # nan_rep too big
1013+ store .append ("sb" , df ["B" ], nan_rep = "bars" )
1014+ with pytest .raises (ValueError , match = msg ):
1015+ store .append ("sb" , df_nan ["B" ])
1016+
1017+ # smaller modified nan_rep
1018+ store .append ("sc" , df ["A" ], nan_rep = "n" )
1019+ store .append ("sc" , df_nan ["A" ])
1020+ result = store ["sc" ]
1021+ expected = concat ([df ["A" ], df_nan ["A" ]])
1022+ tm .assert_series_equal (result , expected )
0 commit comments