@@ -2685,6 +2685,41 @@ def test_construct_with_strings_and_none(self):
26852685 expected = DataFrame ({"a" : ["1" , "2" , None ]}, dtype = "str" )
26862686 tm .assert_frame_equal (df , expected )
26872687
2688+ def test_frame_string_inference (self ):
2689+ # GH#54430
2690+ pa = pytest .importorskip ("pyarrow" )
2691+ dtype = pd .ArrowDtype (pa .string ())
2692+ expected = DataFrame (
2693+ {"a" : ["a" , "b" ]}, dtype = dtype , columns = Index (["a" ], dtype = dtype )
2694+ )
2695+ with pd .option_context ("future.infer_string" , True ):
2696+ df = DataFrame ({"a" : ["a" , "b" ]})
2697+ tm .assert_frame_equal (df , expected )
2698+
2699+ expected = DataFrame (
2700+ {"a" : ["a" , "b" ]},
2701+ dtype = dtype ,
2702+ columns = Index (["a" ], dtype = dtype ),
2703+ index = Index (["x" , "y" ], dtype = dtype ),
2704+ )
2705+ with pd .option_context ("future.infer_string" , True ):
2706+ df = DataFrame ({"a" : ["a" , "b" ]}, index = ["x" , "y" ])
2707+ tm .assert_frame_equal (df , expected )
2708+
2709+ expected = DataFrame (
2710+ {"a" : ["a" , 1 ]}, dtype = "object" , columns = Index (["a" ], dtype = dtype )
2711+ )
2712+ with pd .option_context ("future.infer_string" , True ):
2713+ df = DataFrame ({"a" : ["a" , 1 ]})
2714+ tm .assert_frame_equal (df , expected )
2715+
2716+ expected = DataFrame (
2717+ {"a" : ["a" , "b" ]}, dtype = "object" , columns = Index (["a" ], dtype = dtype )
2718+ )
2719+ with pd .option_context ("future.infer_string" , True ):
2720+ df = DataFrame ({"a" : ["a" , "b" ]}, dtype = "object" )
2721+ tm .assert_frame_equal (df , expected )
2722+
26882723
26892724class TestDataFrameConstructorIndexInference :
26902725 def test_frame_from_dict_of_series_overlapping_monthly_period_indexes (self ):
0 commit comments