@@ -153,8 +153,10 @@ def _compare_columns(
153153 )
154154 return col_left .eq_missing (col_right )
155155
156- if _different_enums (dtype_left , dtype_right ) or _enum_and_categorical (
157- dtype_left , dtype_right
156+ if (
157+ _different_enums (dtype_left , dtype_right )
158+ or _different_categoricals (dtype_left , dtype_right )
159+ or _enum_and_categorical (dtype_left , dtype_right )
158160 ):
159161 # Enums with different categories as well as enums and categoricals
160162 # can't be compared directly.
@@ -267,6 +269,7 @@ def _needs_element_wise_comparison(
267269 _is_float_numeric_pair (dtype_left , dtype_right )
268270 or _is_temporal_pair (dtype_left , dtype_right )
269271 or _different_enums (dtype_left , dtype_right )
272+ or _different_categoricals (dtype_left , dtype_right )
270273 or _enum_and_categorical (dtype_left , dtype_right )
271274 ):
272275 return True
@@ -322,6 +325,16 @@ def _different_enums(
322325 return isinstance (left , pl .Enum ) and isinstance (right , pl .Enum ) and left != right
323326
324327
328+ def _different_categoricals (
329+ left : DataType | DataTypeClass , right : DataType | DataTypeClass
330+ ) -> bool :
331+ return (
332+ isinstance (left , pl .Categorical )
333+ and isinstance (right , pl .Categorical )
334+ and left != right
335+ )
336+
337+
325338def _enum_and_categorical (
326339 left : DataType | DataTypeClass , right : DataType | DataTypeClass
327340) -> bool :
0 commit comments