Skip to content

Commit 801b39e

Browse files
committed
Moved type conversion within add and radd if statement, removed datearray and timedelta catch
1 parent 06bcebc commit 801b39e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,16 +865,21 @@ def _op_method_error_message(self, other, op) -> str:
865865
def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
866866
pa_type = self._pa_array.type
867867
other_original = other
868-
other_NA = self._box_pa(other)
869-
# pyarrow gets upset if you try to join a NullArray
870-
other = other_NA.cast(pa_type)
868+
other = self._box_pa(other)
871869

872870
if (
873871
pa.types.is_string(pa_type)
874872
or pa.types.is_large_string(pa_type)
875873
or pa.types.is_binary(pa_type)
876874
):
877875
if op in [operator.add, roperator.radd]:
876+
# pyarrow gets upset if you try to join a NullArray
877+
if (
878+
pa.types.is_integer(other.type)
879+
or pa.types.is_floating(other.type)
880+
or pa.types.is_null(other.type)
881+
):
882+
other = other.cast(pa_type)
878883
sep = pa.scalar("", type=pa_type)
879884
try:
880885
if op is operator.add:
@@ -888,7 +893,7 @@ def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
888893
return self._from_pyarrow_array(result)
889894
elif op in [operator.mul, roperator.rmul]:
890895
binary = self._pa_array
891-
integral = other_NA
896+
integral = other
892897
if not pa.types.is_integer(integral.type):
893898
raise TypeError("Can only string multiply by an integer.")
894899
pa_integral = pc.if_else(pc.less(integral, 0), 0, integral)
@@ -906,6 +911,13 @@ def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
906911
pa_integral = pc.if_else(pc.less(integral, 0), 0, integral)
907912
result = pc.binary_repeat(binary, pa_integral)
908913
return type(self)(result)
914+
if (
915+
isinstance(other, pa.Scalar)
916+
and pc.is_null(other).as_py()
917+
and op.__name__ in ARROW_LOGICAL_FUNCS
918+
):
919+
# pyarrow kleene ops require null to be typed
920+
other = other.cast(pa_type)
909921

910922
pc_func = arrow_funcs[op.__name__]
911923
if pc_func is NotImplemented:

pandas/core/frame.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8452,10 +8452,7 @@ def _maybe_align_series_as_frame(self, series: Series, axis: AxisInt):
84528452
rvalues = series._values
84538453
if isinstance(rvalues, PeriodArray):
84548454
return series
8455-
if not isinstance(rvalues, np.ndarray) and rvalues.dtype not in (
8456-
"datetime64[ns]",
8457-
"timedelta64[ns]",
8458-
):
8455+
if not isinstance(rvalues, np.ndarray):
84598456
if axis == 0:
84608457
df = DataFrame(dict.fromkeys(range(self.shape[1]), rvalues))
84618458
else:

0 commit comments

Comments
 (0)