@@ -34,22 +34,27 @@ def test_convert_empty(self):
34
34
# Empty DataFrame can pass convert_dtypes, see GH#40393
35
35
empty_df = pd .DataFrame ()
36
36
tm .assert_frame_equal (empty_df , empty_df .convert_dtypes ())
37
-
37
+
38
38
def test_convert_empty_categorical_to_pyarrow (self ):
39
+ # GH#59934
39
40
df = pd .DataFrame (
40
41
{
41
- "A" : pd .Series ( pd . Categorical ([None ] * 5 ) ),
42
- "B" : pd .Series ( pd . Categorical ([None ] * 5 , categories = ["B1" , "B2" ]) ),
43
- }
42
+ "A" : pd .Categorical ([None ] * 5 ),
43
+ "B" : pd .Categorical ([None ] * 5 , categories = ["B1" , "B2" ]),
44
+ }
44
45
)
45
46
converted = df .convert_dtypes (dtype_backend = "pyarrow" )
46
47
expected = df
47
48
tm .assert_frame_equal (converted , expected )
48
-
49
- assert df .A .dtype == "category" , "Dtype in column A is not 'category'"
50
- assert df .B .dtype == "category" , "Dtype in column B is not 'category'"
51
- assert df .A .cat .categories .empty , "Categories in column A are not empty"
52
- assert (df .B .cat .categories == ["B1" , "B2" ]).all (), "Categories in column A are not empty"
49
+
50
+ assert converted .A .dtype == "category" , "Dtype in column A is not 'category'"
51
+ assert converted .B .dtype == "category" , "Dtype in column B is not 'category'"
52
+ assert converted .A .cat .categories .empty , "Categories in column A are not empty"
53
+ assert converted .B .cat .categories .__contains__ (
54
+ "B1"
55
+ ) and converted .B .cat .categories .__contains__ (
56
+ "B2"
57
+ ), "Categories in column B doesn't contain adequate categories"
53
58
54
59
def test_convert_dtypes_retain_column_names (self ):
55
60
# GH#41435
0 commit comments