@@ -883,16 +883,23 @@ def _convert_from_pandas(
883
883
if hasattr (self , "X_model_spec_" ):
884
884
return self .X_model_spec_ .get_model_matrix (df , context = context )
885
885
886
- cat_missing_method_after_alignment = self . cat_missing_method
886
+ cat_missing_method_after_alignment = getattr ( self , " cat_missing_method" , "fail" )
887
887
888
888
if hasattr (self , "feature_dtypes_" ):
889
889
df = _align_df_categories (
890
890
df ,
891
891
self .feature_dtypes_ ,
892
- self .has_missing_category_ ,
893
- self .cat_missing_method ,
892
+ getattr (
893
+ self ,
894
+ "has_missing_category_" ,
895
+ {f : False for f in self .feature_dtypes_ .keys ()},
896
+ ),
897
+ getattr (self , "cat_missing_method" , "fail" ),
894
898
)
895
- if self .cat_missing_method == "convert" :
899
+ if (
900
+ hasattr (self , "categorical_format" )
901
+ and self .cat_missing_method == "convert"
902
+ ):
896
903
df = _add_missing_categories (
897
904
df = df ,
898
905
dtypes = self .feature_dtypes_ ,
@@ -906,7 +913,10 @@ def _convert_from_pandas(
906
913
X = tm .from_pandas (
907
914
df ,
908
915
drop_first = self .drop_first ,
909
- categorical_format = self .categorical_format ,
916
+ # prior to v3, categorical format used underscore
917
+ categorical_format = getattr (
918
+ self , "categorical_format" , "{name}__{category}"
919
+ ),
910
920
cat_missing_method = cat_missing_method_after_alignment ,
911
921
)
912
922
@@ -2724,7 +2734,8 @@ def _set_up_and_check_fit_args(
2724
2734
2725
2735
self .feature_dtypes_ = X .dtypes .to_dict ()
2726
2736
self .has_missing_category_ = {
2727
- col : (self .cat_missing_method == "convert" ) and X [col ].isna ().any ()
2737
+ col : (getattr (self , "cat_missing_method" , "fail" ) == "convert" )
2738
+ and X [col ].isna ().any ()
2728
2739
for col , dtype in self .feature_dtypes_ .items ()
2729
2740
if isinstance (dtype , pd .CategoricalDtype )
2730
2741
}
@@ -2784,9 +2795,11 @@ def _expand_categorical_penalties(
2784
2795
X = tm .from_pandas (
2785
2796
X ,
2786
2797
drop_first = self .drop_first ,
2787
- categorical_format = self .categorical_format ,
2788
- cat_missing_method = self .cat_missing_method ,
2789
- cat_missing_name = self .cat_missing_name ,
2798
+ categorical_format = getattr (
2799
+ self , "categorical_format" , "{name}__{category}"
2800
+ ),
2801
+ cat_missing_method = getattr (self , "cat_missing_method" , "fail" ),
2802
+ cat_missing_name = getattr (self , "cat_missing_name" , "(MISSING)" ),
2790
2803
)
2791
2804
2792
2805
if y is None :
0 commit comments