@@ -659,31 +659,34 @@ def test_dtype_backend_and_dtype(self, read_ext):
659
659
@pytest .mark .xfail (
660
660
using_string_dtype (), reason = "infer_string takes precedence" , strict = False
661
661
)
662
- def test_dtype_backend_string (self , read_ext , string_storage , tmp_excel ):
662
+ def test_dtype_backend_string (self , read_ext , string_storage ):
663
663
# GH#36712
664
664
if read_ext in (".xlsb" , ".xls" ):
665
665
pytest .skip (f"No engine for filetype: '{ read_ext } '" )
666
666
667
- df = DataFrame (
668
- {
669
- "a" : np .array (["a" , "b" ], dtype = np .object_ ),
670
- "b" : np .array (["x" , pd .NA ], dtype = np .object_ ),
671
- }
672
- )
673
- df .to_excel (tmp_excel , sheet_name = "test" , index = False )
674
-
675
667
with pd .option_context ("mode.string_storage" , string_storage ):
676
- result = pd .read_excel (
677
- tmp_excel , sheet_name = "test" , dtype_backend = "numpy_nullable"
668
+ df = DataFrame (
669
+ {
670
+ "a" : np .array (["a" , "b" ], dtype = np .object_ ),
671
+ "b" : np .array (["x" , pd .NA ], dtype = np .object_ ),
672
+ }
678
673
)
679
674
680
- expected = DataFrame (
681
- {
682
- "a" : Series (["a" , "b" ], dtype = pd .StringDtype (string_storage )),
683
- "b" : Series (["x" , None ], dtype = pd .StringDtype (string_storage )),
684
- }
685
- )
686
- tm .assert_frame_equal (result , expected )
675
+ with tm .ensure_clean (read_ext ) as file_path :
676
+ df .to_excel (file_path , sheet_name = "test" , index = False )
677
+ result = pd .read_excel (
678
+ file_path , sheet_name = "test" , dtype_backend = "numpy_nullable"
679
+ )
680
+
681
+ expected = DataFrame (
682
+ {
683
+ "a" : Series (["a" , "b" ], dtype = pd .StringDtype (string_storage )),
684
+ "b" : Series (["x" , None ], dtype = pd .StringDtype (string_storage )),
685
+ }
686
+ )
687
+ # the storage of the str columns' Index is also affected by the
688
+ # string_storage setting -> ignore that for checking the result
689
+ tm .assert_frame_equal (result , expected , check_column_type = False )
687
690
688
691
@pytest .mark .parametrize ("dtypes, exp_value" , [({}, 1 ), ({"a.1" : "int64" }, 1 )])
689
692
def test_dtype_mangle_dup_cols (self , read_ext , dtypes , exp_value ):
0 commit comments