Skip to content

Commit 6ca4461

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into cln-pytables-sigs
2 parents 74f31f2 + cc5b417 commit 6ca4461

File tree

11 files changed

+181
-167
lines changed

11 files changed

+181
-167
lines changed

pandas/core/ops/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ def wrapper(left, right):
462462
res_name = get_op_result_name(left, right)
463463

464464
lvalues = extract_array(left, extract_numpy=True)
465-
result = arithmetic_op(lvalues, right, op, str_rep)
465+
rvalues = extract_array(right, extract_numpy=True)
466+
result = arithmetic_op(lvalues, rvalues, op, str_rep)
466467

467468
return _construct_result(left, result, index=left.index, name=res_name)
468469

pandas/core/ops/array_ops.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@
2424
)
2525
from pandas.core.dtypes.generic import (
2626
ABCDatetimeArray,
27-
ABCDatetimeIndex,
2827
ABCExtensionArray,
2928
ABCIndex,
3029
ABCIndexClass,
3130
ABCSeries,
3231
ABCTimedeltaArray,
33-
ABCTimedeltaIndex,
3432
)
3533
from pandas.core.dtypes.missing import isna, notna
3634

37-
from pandas.core.construction import extract_array
3835
from pandas.core.ops import missing
3936
from pandas.core.ops.dispatch import dispatch_to_extension_op, should_extension_dispatch
4037
from pandas.core.ops.invalid import invalid_comparison
@@ -178,22 +175,10 @@ def arithmetic_op(
178175

179176
from pandas.core.ops import maybe_upcast_for_op
180177

181-
keep_null_freq = isinstance(
182-
right,
183-
(
184-
ABCDatetimeIndex,
185-
ABCDatetimeArray,
186-
ABCTimedeltaIndex,
187-
ABCTimedeltaArray,
188-
Timestamp,
189-
),
190-
)
191-
192-
# NB: We assume that extract_array has already been called on `left`, but
193-
# cannot make the same assumption about `right`. This is because we need
194-
# to define `keep_null_freq` before calling extract_array on it.
178+
# NB: We assume that extract_array has already been called
179+
# on `left` and `right`.
195180
lvalues = left
196-
rvalues = extract_array(right, extract_numpy=True)
181+
rvalues = right
197182

198183
rvalues = maybe_upcast_for_op(rvalues, lvalues.shape)
199184

@@ -203,7 +188,7 @@ def arithmetic_op(
203188
# TimedeltaArray, DatetimeArray, and Timestamp are included here
204189
# because they have `freq` attribute which is handled correctly
205190
# by dispatch_to_extension_op.
206-
res_values = dispatch_to_extension_op(op, lvalues, rvalues, keep_null_freq)
191+
res_values = dispatch_to_extension_op(op, lvalues, rvalues)
207192

208193
else:
209194
with np.errstate(all="ignore"):

pandas/core/ops/dispatch.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import numpy as np
77

8-
from pandas.errors import NullFrequencyError
9-
108
from pandas.core.dtypes.common import (
119
is_datetime64_dtype,
1210
is_extension_array_dtype,
@@ -97,10 +95,7 @@ def should_series_dispatch(left, right, op):
9795

9896

9997
def dispatch_to_extension_op(
100-
op,
101-
left: Union[ABCExtensionArray, np.ndarray],
102-
right: Any,
103-
keep_null_freq: bool = False,
98+
op, left: Union[ABCExtensionArray, np.ndarray], right: Any,
10499
):
105100
"""
106101
Assume that left or right is a Series backed by an ExtensionArray,
@@ -111,9 +106,6 @@ def dispatch_to_extension_op(
111106
op : binary operator
112107
left : ExtensionArray or np.ndarray
113108
right : object
114-
keep_null_freq : bool, default False
115-
Whether to re-raise a NullFrequencyError unchanged, as opposed to
116-
catching and raising TypeError.
117109
118110
Returns
119111
-------
@@ -131,20 +123,7 @@ def dispatch_to_extension_op(
131123

132124
# The op calls will raise TypeError if the op is not defined
133125
# on the ExtensionArray
134-
135-
try:
136-
res_values = op(left, right)
137-
except NullFrequencyError:
138-
# DatetimeIndex and TimedeltaIndex with freq == None raise ValueError
139-
# on add/sub of integers (or int-like). We re-raise as a TypeError.
140-
if keep_null_freq:
141-
# TODO: remove keep_null_freq after Timestamp+int deprecation
142-
# GH#22535 is enforced
143-
raise
144-
raise TypeError(
145-
"incompatible type for a datetime/timedelta "
146-
"operation [{name}]".format(name=op.__name__)
147-
)
126+
res_values = op(left, right)
148127
return res_values
149128

150129

0 commit comments

Comments
 (0)