|
38 | 38 | is_bool_dtype,
|
39 | 39 | is_list_like,
|
40 | 40 | is_numeric_v_string_like,
|
| 41 | + is_string_dtype, |
41 | 42 | is_object_dtype,
|
42 | 43 | is_scalar,
|
43 | 44 | )
|
|
53 | 54 |
|
54 | 55 | from pandas.core import roperator
|
55 | 56 | from pandas.core.computation import expressions
|
56 |
| -from pandas.core.construction import ensure_wrapped_if_datetimelike |
| 57 | +from pandas.core.construction import ensure_wrapped_if_datetimelike, array |
57 | 58 | from pandas.core.ops import missing
|
58 | 59 | from pandas.core.ops.dispatch import should_extension_dispatch
|
59 | 60 | from pandas.core.ops.invalid import invalid_comparison
|
@@ -321,6 +322,17 @@ def comparison_op(left: ArrayLike, right: Any, op) -> ArrayLike:
|
321 | 322 | "Lengths must match to compare", lvalues.shape, rvalues.shape
|
322 | 323 | )
|
323 | 324 |
|
| 325 | + if ( |
| 326 | + (is_string_dtype(lvalues) and is_object_dtype(rvalues)) or |
| 327 | + (is_object_dtype(lvalues) and is_string_dtype(rvalues)) |
| 328 | + ): |
| 329 | + if lvalues.dtype.name == "string" and rvalues.dtype == object: |
| 330 | + lvalues = lvalues.astype("string") |
| 331 | + rvalues = array(rvalues, dtype="string") |
| 332 | + elif rvalues.dtype.name == "string" and lvalues.dtype == object: |
| 333 | + rvalues = rvalues.astype("string") |
| 334 | + lvalues = array(lvalues, dtype="string") |
| 335 | + |
324 | 336 | if should_extension_dispatch(lvalues, rvalues) or (
|
325 | 337 | (isinstance(rvalues, (Timedelta, BaseOffset, Timestamp)) or right is NaT)
|
326 | 338 | and lvalues.dtype != object
|
|
0 commit comments