File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -12016,25 +12016,25 @@ def _transform_ord_cat_cols_to_coded_cols(self) -> DataFrame:
1201612016 if len (categ .columns ) == 0 :
1201712017 return self
1201812018
12019+ data = self .copy (deep = False )
1201912020 cols_convert = categ .loc [:, categ .agg (lambda x : x .cat .ordered )].columns .unique ()
12020- single_cols = [col for col in cols_convert if isinstance (categ [col ], Series )]
12021+ single_cols = [col for col in cols_convert if isinstance (data [col ], Series )]
1202112022 duplicated_cols = [
12022- col for col in cols_convert if isinstance (categ [col ], DataFrame )
12023+ col for col in cols_convert if isinstance (data [col ], DataFrame )
1202312024 ]
1202412025
1202512026 if not single_cols and not duplicated_cols :
1202612027 return self
1202712028
12028- data = self .copy (deep = False )
1202912029 if single_cols :
12030- data [single_cols ] = data [single_cols ].transform (
12030+ data [single_cols ] = data [single_cols ].apply (
1203112031 lambda x : x .cat .codes .replace (- 1 , np .nan )
1203212032 )
1203312033
1203412034 if duplicated_cols :
1203512035 data [duplicated_cols ] = data [duplicated_cols ].apply (
1203612036 lambda x : x .cat .codes .replace (- 1 , np .nan )
12037- if isinstance (x , CategoricalDtype ) and bool (x .ordered )
12037+ if isinstance (x . dtype , CategoricalDtype ) and bool (x . dtype .ordered )
1203812038 else x
1203912039 )
1204012040
You can’t perform that action at this time.
0 commit comments