Skip to content

REF: use should_extension_dispatch for comparison method #27912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Aug 19, 2019
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e18a291
REF: implement should_extension_dispatch
jbrockmendel Aug 8, 2019
10eacc4
dummy to force CI
jbrockmendel Aug 8, 2019
731ac49
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 8, 2019
79d6abe
Dummy to force CI
jbrockmendel Aug 8, 2019
919d015
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 12, 2019
28b287f
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 13, 2019
9f5bf6e
add types
jbrockmendel Aug 13, 2019
7295a9e
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 13, 2019
69ea8a2
BUG: fix Sparse reduction (#27890)
jbrockmendel Aug 13, 2019
8b8bca0
use should_extension_dispatch
jbrockmendel Aug 14, 2019
57892a1
simplify comparison method
jbrockmendel Aug 14, 2019
b119a24
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 14, 2019
4b9ce68
fix numpy warning
jbrockmendel Aug 14, 2019
4f31a3b
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 14, 2019
1d414df
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 15, 2019
69f7db2
fix deprecationwaring
jbrockmendel Aug 15, 2019
c2df30a
catch better
jbrockmendel Aug 15, 2019
1ef0be1
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 15, 2019
97f75dc
Fix check
jbrockmendel Aug 15, 2019
dddd0af
Merge branch 'master' of https://github.com/pandas-dev/pandas into sh…
jbrockmendel Aug 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
from pandas.core.dtypes.common import (
ensure_object,
is_bool_dtype,
is_categorical_dtype,
is_datetime64_dtype,
is_datetime64tz_dtype,
is_datetimelike_v_numeric,
is_extension_array_dtype,
is_integer_dtype,
Expand All @@ -32,6 +30,7 @@
ABCDataFrame,
ABCDatetimeArray,
ABCDatetimeIndex,
ABCExtensionArray,
ABCIndexClass,
ABCSeries,
ABCSparseSeries,
Expand Down Expand Up @@ -699,42 +698,17 @@ def wrapper(self, other, axis=None):

if isinstance(other, ABCSeries) and not self._indexed_same(other):
raise ValueError("Can only compare identically-labeled Series objects")
elif (
is_list_like(other)
and len(other) != len(self)
and not isinstance(other, (set, frozenset))
):
raise ValueError("Lengths must match")

elif isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries)):
elif isinstance(
other, (np.ndarray, ABCExtensionArray, ABCIndexClass, ABCSeries)
):
# TODO: make this treatment consistent across ops and classes.
# We are not catching all listlikes here (e.g. frozenset, tuple)
# The ambiguous case is object-dtype. See GH#27803
if len(self) != len(other):
raise ValueError("Lengths must match to compare")

if is_categorical_dtype(self):
# Dispatch to Categorical implementation; CategoricalIndex
# behavior is non-canonical GH#19513
res_values = dispatch_to_extension_op(op, self, other)

elif is_datetime64_dtype(self) or is_datetime64tz_dtype(self):
# Dispatch to DatetimeIndex to ensure identical
# Series/Index behavior
from pandas.core.arrays import DatetimeArray

res_values = dispatch_to_extension_op(op, DatetimeArray(self), other)

elif is_timedelta64_dtype(self):
from pandas.core.arrays import TimedeltaArray

res_values = dispatch_to_extension_op(op, TimedeltaArray(self), other)

elif is_extension_array_dtype(self) or (
is_extension_array_dtype(other) and not is_scalar(other)
):
# Note: the `not is_scalar(other)` condition rules out
# e.g. other == "category"
if should_extension_dispatch(self, other):
res_values = dispatch_to_extension_op(op, self, other)

elif is_scalar(other) and isna(other):
Expand Down