2525 ensure_clean_store ,
2626)
2727
28- pytestmark = [
29- pytest .mark .single_cpu ,
30- pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False ),
31- ]
28+ pytestmark = [pytest .mark .single_cpu ]
3229
3330tables = pytest .importorskip ("tables" )
3431
@@ -40,7 +37,7 @@ def test_append(setup_path):
4037 # tables.NaturalNameWarning):
4138 df = DataFrame (
4239 np .random .default_rng (2 ).standard_normal ((20 , 4 )),
43- columns = Index (list ("ABCD" ), dtype = object ),
40+ columns = Index (list ("ABCD" )),
4441 index = date_range ("2000-01-01" , periods = 20 , freq = "B" ),
4542 )
4643 _maybe_remove (store , "df1" )
@@ -201,7 +198,7 @@ def test_append_some_nans(setup_path):
201198 tm .assert_frame_equal (store ["df3" ], df3 , check_index_type = True )
202199
203200
204- def test_append_all_nans (setup_path ):
201+ def test_append_all_nans (setup_path , using_infer_string ):
205202 with ensure_clean_store (setup_path ) as store :
206203 df = DataFrame (
207204 {
@@ -253,7 +250,13 @@ def test_append_all_nans(setup_path):
253250 _maybe_remove (store , "df" )
254251 store .append ("df" , df [:10 ], dropna = True )
255252 store .append ("df" , df [10 :], dropna = True )
256- tm .assert_frame_equal (store ["df" ], df , check_index_type = True )
253+ result = store ["df" ]
254+ expected = df
255+ if using_infer_string :
256+ # TODO: Test is incorrect when not using_infer_string.
257+ # Should take the last 4 rows uncondiationally.
258+ expected = expected [- 4 :]
259+ tm .assert_frame_equal (result , expected , check_index_type = True )
257260
258261 _maybe_remove (store , "df2" )
259262 store .append ("df2" , df [:10 ], dropna = False )
@@ -292,7 +295,7 @@ def test_append_frame_column_oriented(setup_path):
292295 # column oriented
293296 df = DataFrame (
294297 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
295- columns = Index (list ("ABCD" ), dtype = object ),
298+ columns = Index (list ("ABCD" )),
296299 index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
297300 )
298301 df .index = df .index ._with_freq (None ) # freq doesn't round-trip
@@ -417,7 +420,7 @@ def check_col(key, name, size):
417420 {
418421 "A" : [0.0 , 1.0 , 2.0 , 3.0 , 4.0 ],
419422 "B" : [0.0 , 1.0 , 0.0 , 1.0 , 0.0 ],
420- "C" : Index (["foo1" , "foo2" , "foo3" , "foo4" , "foo5" ], dtype = object ),
423+ "C" : Index (["foo1" , "foo2" , "foo3" , "foo4" , "foo5" ]),
421424 "D" : date_range ("20130101" , periods = 5 ),
422425 }
423426 ).set_index ("C" )
@@ -444,7 +447,7 @@ def check_col(key, name, size):
444447 _maybe_remove (store , "df" )
445448 df = DataFrame (
446449 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
447- columns = Index (list ("ABCD" ), dtype = object ),
450+ columns = Index (list ("ABCD" )),
448451 index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
449452 )
450453 df ["string" ] = "foo"
@@ -504,11 +507,12 @@ def test_append_with_empty_string(setup_path):
504507 tm .assert_frame_equal (store .select ("df" ), df )
505508
506509
510+ @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
507511def test_append_with_data_columns (setup_path ):
508512 with ensure_clean_store (setup_path ) as store :
509513 df = DataFrame (
510514 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
511- columns = Index (list ("ABCD" ), dtype = object ),
515+ columns = Index (list ("ABCD" )),
512516 index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
513517 )
514518 df .iloc [0 , df .columns .get_loc ("B" )] = 1.0
@@ -684,8 +688,8 @@ def test_append_misc(setup_path):
684688 with ensure_clean_store (setup_path ) as store :
685689 df = DataFrame (
686690 1.1 * np .arange (120 ).reshape ((30 , 4 )),
687- columns = Index (list ("ABCD" ), dtype = object ),
688- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
691+ columns = Index (list ("ABCD" )),
692+ index = Index ([f"i-{ i } " for i in range (30 )]),
689693 )
690694 store .append ("df" , df , chunksize = 1 )
691695 result = store .select ("df" )
@@ -701,8 +705,8 @@ def test_append_misc_chunksize(setup_path, chunksize):
701705 # more chunksize in append tests
702706 df = DataFrame (
703707 1.1 * np .arange (120 ).reshape ((30 , 4 )),
704- columns = Index (list ("ABCD" ), dtype = object ),
705- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
708+ columns = Index (list ("ABCD" )),
709+ index = Index ([f"i-{ i } " for i in range (30 )]),
706710 )
707711 df ["string" ] = "foo"
708712 df ["float322" ] = 1.0
@@ -742,15 +746,15 @@ def test_append_misc_empty_frame(setup_path):
742746# the conversion from AM->BM converts the invalid object dtype column into
743747# a datetime64 column no longer raising an error
744748@td .skip_array_manager_not_yet_implemented
745- def test_append_raise (setup_path ):
749+ def test_append_raise (setup_path , using_infer_string ):
746750 with ensure_clean_store (setup_path ) as store :
747751 # test append with invalid input to get good error messages
748752
749753 # list in column
750754 df = DataFrame (
751755 1.1 * np .arange (120 ).reshape ((30 , 4 )),
752- columns = Index (list ("ABCD" ), dtype = object ),
753- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
756+ columns = Index (list ("ABCD" )),
757+ index = Index ([f"i-{ i } " for i in range (30 )]),
754758 )
755759 df ["invalid" ] = [["a" ]] * len (df )
756760 assert df .dtypes ["invalid" ] == np .object_
@@ -770,8 +774,8 @@ def test_append_raise(setup_path):
770774 # datetime with embedded nans as object
771775 df = DataFrame (
772776 1.1 * np .arange (120 ).reshape ((30 , 4 )),
773- columns = Index (list ("ABCD" ), dtype = object ),
774- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
777+ columns = Index (list ("ABCD" )),
778+ index = Index ([f"i-{ i } " for i in range (30 )]),
775779 )
776780 s = Series (datetime .datetime (2001 , 1 , 2 ), index = df .index )
777781 s = s .astype (object )
@@ -798,8 +802,8 @@ def test_append_raise(setup_path):
798802 # appending an incompatible table
799803 df = DataFrame (
800804 1.1 * np .arange (120 ).reshape ((30 , 4 )),
801- columns = Index (list ("ABCD" ), dtype = object ),
802- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
805+ columns = Index (list ("ABCD" )),
806+ index = Index ([f"i-{ i } " for i in range (30 )]),
803807 )
804808 store .append ("df" , df )
805809
@@ -876,7 +880,7 @@ def test_append_with_timedelta(setup_path):
876880def test_append_to_multiple (setup_path ):
877881 df1 = DataFrame (
878882 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
879- columns = Index (list ("ABCD" ), dtype = object ),
883+ columns = Index (list ("ABCD" )),
880884 index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
881885 )
882886 df2 = df1 .copy ().rename (columns = "{}_2" .format )
@@ -913,12 +917,12 @@ def test_append_to_multiple(setup_path):
913917def test_append_to_multiple_dropna (setup_path ):
914918 df1 = DataFrame (
915919 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
916- columns = Index (list ("ABCD" ), dtype = object ),
920+ columns = Index (list ("ABCD" )),
917921 index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
918922 )
919923 df2 = DataFrame (
920924 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
921- columns = Index (list ("ABCD" ), dtype = object ),
925+ columns = Index (list ("ABCD" )),
922926 index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
923927 ).rename (columns = "{}_2" .format )
924928 df1 .iloc [1 , df1 .columns .get_indexer (["A" , "B" ])] = np .nan
@@ -938,7 +942,7 @@ def test_append_to_multiple_dropna(setup_path):
938942def test_append_to_multiple_dropna_false (setup_path ):
939943 df1 = DataFrame (
940944 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
941- columns = Index (list ("ABCD" ), dtype = object ),
945+ columns = Index (list ("ABCD" )),
942946 index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
943947 )
944948 df2 = df1 .copy ().rename (columns = "{}_2" .format )
0 commit comments