@@ -2429,18 +2429,36 @@ def where(self, cond, other=np.nan):
24292429 tmp_other_col_name = '__tmp_other_col_{}__' .format
24302430
24312431 kdf = self .copy ()
2432+
2433+ tmp_cond_col_names = [tmp_cond_col_name (name_like_string (label ))
2434+ for label in self ._internal .column_labels ]
24322435 if isinstance (cond , DataFrame ):
2433- for label in self ._internal .column_labels :
2434- kdf [tmp_cond_col_name (name_like_string (label ))] = cond .get (label , False )
2436+ cond = cond [[(cond ._internal .scol_for (label )
2437+ if label in cond ._internal .column_labels else F .lit (False )).alias (name )
2438+ for label , name
2439+ in zip (self ._internal .column_labels , tmp_cond_col_names )]]
2440+ kdf [tmp_cond_col_names ] = cond
24352441 elif isinstance (cond , Series ):
2436- for label in self ._internal .column_labels :
2437- kdf [tmp_cond_col_name (name_like_string (label ))] = cond
2442+ cond = cond .to_frame ()
2443+ cond = cond [[cond ._internal .column_scols [0 ].alias (name ) for name in tmp_cond_col_names ]]
2444+ kdf [tmp_cond_col_names ] = cond
24382445 else :
24392446 raise ValueError ("type of cond must be a DataFrame or Series" )
24402447
2448+ tmp_other_col_names = [tmp_other_col_name (name_like_string (label ))
2449+ for label in self ._internal .column_labels ]
24412450 if isinstance (other , DataFrame ):
2442- for label in self ._internal .column_labels :
2443- kdf [tmp_other_col_name (name_like_string (label ))] = other .get (label , np .nan )
2451+ other = other [[(other ._internal .scol_for (label )
2452+ if label in other ._internal .column_labels else F .lit (np .nan ))
2453+ .alias (name )
2454+ for label , name
2455+ in zip (self ._internal .column_labels , tmp_other_col_names )]]
2456+ kdf [tmp_other_col_names ] = other
2457+ elif isinstance (other , Series ):
2458+ other = other .to_frame ()
2459+ other = other [[other ._internal .column_scols [0 ].alias (name )
2460+ for name in tmp_other_col_names ]]
2461+ kdf [tmp_other_col_names ] = other
24442462 else :
24452463 for label in self ._internal .column_labels :
24462464 kdf [tmp_other_col_name (name_like_string (label ))] = other
0 commit comments