|
17 | 17 | from pandas.core.dtypes.common import (
|
18 | 18 | ensure_object,
|
19 | 19 | is_bool_dtype,
|
20 |
| - is_categorical_dtype, |
21 | 20 | is_datetime64_dtype,
|
22 |
| - is_datetime64tz_dtype, |
23 | 21 | is_datetimelike_v_numeric,
|
24 | 22 | is_extension_array_dtype,
|
25 | 23 | is_integer_dtype,
|
|
32 | 30 | ABCDataFrame,
|
33 | 31 | ABCDatetimeArray,
|
34 | 32 | ABCDatetimeIndex,
|
| 33 | + ABCExtensionArray, |
35 | 34 | ABCIndexClass,
|
36 | 35 | ABCSeries,
|
37 | 36 | ABCSparseSeries,
|
@@ -699,42 +698,17 @@ def wrapper(self, other, axis=None):
|
699 | 698 |
|
700 | 699 | if isinstance(other, ABCSeries) and not self._indexed_same(other):
|
701 | 700 | raise ValueError("Can only compare identically-labeled Series objects")
|
702 |
| - elif ( |
703 |
| - is_list_like(other) |
704 |
| - and len(other) != len(self) |
705 |
| - and not isinstance(other, (set, frozenset)) |
706 |
| - ): |
707 |
| - raise ValueError("Lengths must match") |
708 | 701 |
|
709 |
| - elif isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries)): |
| 702 | + elif isinstance( |
| 703 | + other, (np.ndarray, ABCExtensionArray, ABCIndexClass, ABCSeries) |
| 704 | + ): |
710 | 705 | # TODO: make this treatment consistent across ops and classes.
|
711 | 706 | # We are not catching all listlikes here (e.g. frozenset, tuple)
|
712 | 707 | # The ambiguous case is object-dtype. See GH#27803
|
713 | 708 | if len(self) != len(other):
|
714 | 709 | raise ValueError("Lengths must match to compare")
|
715 | 710 |
|
716 |
| - if is_categorical_dtype(self): |
717 |
| - # Dispatch to Categorical implementation; CategoricalIndex |
718 |
| - # behavior is non-canonical GH#19513 |
719 |
| - res_values = dispatch_to_extension_op(op, self, other) |
720 |
| - |
721 |
| - elif is_datetime64_dtype(self) or is_datetime64tz_dtype(self): |
722 |
| - # Dispatch to DatetimeIndex to ensure identical |
723 |
| - # Series/Index behavior |
724 |
| - from pandas.core.arrays import DatetimeArray |
725 |
| - |
726 |
| - res_values = dispatch_to_extension_op(op, DatetimeArray(self), other) |
727 |
| - |
728 |
| - elif is_timedelta64_dtype(self): |
729 |
| - from pandas.core.arrays import TimedeltaArray |
730 |
| - |
731 |
| - res_values = dispatch_to_extension_op(op, TimedeltaArray(self), other) |
732 |
| - |
733 |
| - elif is_extension_array_dtype(self) or ( |
734 |
| - is_extension_array_dtype(other) and not is_scalar(other) |
735 |
| - ): |
736 |
| - # Note: the `not is_scalar(other)` condition rules out |
737 |
| - # e.g. other == "category" |
| 711 | + if should_extension_dispatch(self, other): |
738 | 712 | res_values = dispatch_to_extension_op(op, self, other)
|
739 | 713 |
|
740 | 714 | elif is_scalar(other) and isna(other):
|
|
0 commit comments