Skip to content

Commit 4a9f4db

Browse files
committed
Moved type conversion within add and radd if statement, removed datearray and timedelta catch
1 parent 81f4f18 commit 4a9f4db

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,16 +890,21 @@ def _op_method_error_message(self, other, op) -> str:
890890
def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
891891
pa_type = self._pa_array.type
892892
other_original = other
893-
other_NA = self._box_pa(other)
894-
# pyarrow gets upset if you try to join a NullArray
895-
other = other_NA.cast(pa_type)
893+
other = self._box_pa(other)
896894

897895
if (
898896
pa.types.is_string(pa_type)
899897
or pa.types.is_large_string(pa_type)
900898
or pa.types.is_binary(pa_type)
901899
):
902900
if op in [operator.add, roperator.radd]:
901+
# pyarrow gets upset if you try to join a NullArray
902+
if (
903+
pa.types.is_integer(other.type)
904+
or pa.types.is_floating(other.type)
905+
or pa.types.is_null(other.type)
906+
):
907+
other = other.cast(pa_type)
903908
sep = pa.scalar("", type=pa_type)
904909
try:
905910
if op is operator.add:
@@ -913,7 +918,7 @@ def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
913918
return self._from_pyarrow_array(result)
914919
elif op in [operator.mul, roperator.rmul]:
915920
binary = self._pa_array
916-
integral = other_NA
921+
integral = other
917922
if not pa.types.is_integer(integral.type):
918923
raise TypeError("Can only string multiply by an integer.")
919924
pa_integral = pc.if_else(pc.less(integral, 0), 0, integral)

pandas/core/frame.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8470,10 +8470,7 @@ def _maybe_align_series_as_frame(self, series: Series, axis: AxisInt):
84708470
rvalues = series._values
84718471
if isinstance(rvalues, PeriodArray):
84728472
return series
8473-
if not isinstance(rvalues, np.ndarray) and rvalues.dtype not in (
8474-
"datetime64[ns]",
8475-
"timedelta64[ns]",
8476-
):
8473+
if not isinstance(rvalues, np.ndarray):
84778474
if axis == 0:
84788475
df = DataFrame(dict.fromkeys(range(self.shape[1]), rvalues))
84798476
else:

0 commit comments

Comments
 (0)