@@ -799,10 +799,19 @@ def test_categorical_preserve_object_dtype_from_pandas(self):
799799 cat_from_arr = Categorical (arr )
800800 cat_from_list = Categorical (pylist )
801801
802- # Series/Index with object dtype: preserve object dtype
803- assert cat_from_ser .categories .dtype == "object"
804- assert cat_from_idx .categories .dtype == "object"
802+ # Series/Index with object dtype: infer string
803+ # dtype if all elements are strings
804+ assert cat_from_ser .categories .inferred_type == "string"
805+ assert cat_from_idx .categories .inferred_type == "string"
805806
806807 # Numpy array or list: infer string dtype
807- assert cat_from_arr .categories .dtype == "str"
808- assert cat_from_list .categories .dtype == "str"
808+ assert cat_from_arr .categories .inferred_type == "string"
809+ assert cat_from_list .categories .inferred_type == "string"
810+
811+ # Mixed types: preserve object dtype
812+ ser_mixed = Series (["foo" , 1 , None ], dtype = "object" )
813+ idx_mixed = Index (["foo" , 1 , None ], dtype = "object" )
814+ cat_mixed_ser = Categorical (ser_mixed )
815+ cat_mixed_idx = Categorical (idx_mixed )
816+ assert cat_mixed_ser .categories .dtype == "object"
817+ assert cat_mixed_idx .categories .dtype == "object"
0 commit comments