|
57 | 57 | from pandas.core.ops import missing
|
58 | 58 | from pandas.core.ops.dispatch import should_extension_dispatch
|
59 | 59 | from pandas.core.ops.invalid import invalid_comparison
|
60 |
| - |
| 60 | +from pandas.core.frame import DataFrame |
| 61 | +from pandas.core.series import Series |
61 | 62 | if TYPE_CHECKING:
|
62 | 63 | from pandas._typing import (
|
63 | 64 | ArrayLike,
|
@@ -405,6 +406,25 @@ def logical_op(left: ArrayLike, right: Any, op) -> ArrayLike:
|
405 | 406 | -------
|
406 | 407 | ndarray or ExtensionArray
|
407 | 408 | """
|
| 409 | + def logical_operator(left: ArrayLike, right: Any, op) -> ArrayLike: |
| 410 | + # Check if `right` is a Series and `left` is a DataFrame, and apply broadcasting |
| 411 | + if isinstance(left, DataFrame) and isinstance(right, Series): |
| 412 | + right = right.values # Convert Series to array for broadcasting |
| 413 | + |
| 414 | + # Convert right to a scalar or valid object if necessary |
| 415 | + right = lib.item_from_zerodim(right) |
| 416 | + |
| 417 | + # Check for dtype-less sequences (e.g., list, tuple) and raise error |
| 418 | + if is_list_like(right) and not hasattr(right, "dtype"): |
| 419 | + # Raise an error if `right` is a list or tuple without a dtype |
| 420 | + raise TypeError( |
| 421 | + "Logical ops (and, or, xor) between Pandas objects and dtype-less " |
| 422 | + "sequences (e.g., list, tuple) are no longer supported. " |
| 423 | + "Wrap the object in a Series, Index, or np.array before operating." |
| 424 | + ) |
| 425 | + |
| 426 | + # Proceed with the logical operation |
| 427 | + return logical_operator(op(left, right)) |
408 | 428 |
|
409 | 429 | def fill_bool(x, left=None):
|
410 | 430 | # if `left` is specifically not-boolean, we do not cast to bool
|
|
0 commit comments