Skip to content

Commit bca56fe

Browse files
committed
Removed float addition test, reintroduced check for float type nulls
1 parent 4617108 commit bca56fe

File tree

3 files changed

+16
-36
lines changed

3 files changed

+16
-36
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,9 @@ def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
906906
):
907907
if op in [operator.add, roperator.radd]:
908908
sep = pa.scalar("", type=pa_type)
909+
if is_scalar(other) or isinstance(other, pa.Scalar):
910+
if len(other) == 0 or isna(other).any():
911+
other = other.cast(pa_type)
909912
try:
910913
if op is operator.add:
911914
result = pc.binary_join_element_wise(self._pa_array, other, sep)

pandas/tests/arrays/floating/test_arithmetic.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -153,41 +153,8 @@ def test_error_invalid_values(data, all_arithmetic_operators):
153153

154154
# invalid array-likes
155155
str_ser = pd.Series("foo", index=s.index)
156-
if (
157-
all_arithmetic_operators
158-
in [
159-
"__add__",
160-
"__radd__",
161-
]
162-
and pd.options.future.infer_string
163-
):
164-
res = ops(str_ser)
165-
if all_arithmetic_operators == "__radd__":
166-
data_expected = []
167-
for i in data:
168-
if pd.isna(i):
169-
data_expected.append(i)
170-
elif i.is_integer():
171-
data_expected.append("foo" + str(int(i)))
172-
else:
173-
data_expected.append("foo" + str(i))
174-
175-
expected = pd.Series(data_expected, index=s.index)
176-
else:
177-
data_expected = []
178-
for i in data:
179-
if pd.isna(i):
180-
data_expected.append(i)
181-
elif i.is_integer():
182-
data_expected.append(str(int(i)) + "foo")
183-
else:
184-
data_expected.append(str(i) + "foo")
185-
186-
expected = pd.Series(data_expected, index=s.index)
187-
tm.assert_series_equal(res, expected)
188-
else:
189-
with pytest.raises(TypeError, match=msg):
190-
ops(str_ser)
156+
with pytest.raises(TypeError, match=msg):
157+
ops(str_ser)
191158

192159
msg = "|".join(
193160
[

pandas/tests/frame/test_arithmetic.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,17 @@ def test_arith_flex_zero_len_raises(self):
708708
with pytest.raises(TypeError, match=msg):
709709
df.add(ser_len0, fill_value="E")
710710

711-
df_len0.sub(df["A"], axis=None, fill_value=3)
711+
result = df_len0.sub(df, axis=None, fill_value=3)
712+
expected = DataFrame([[2, 1], [0, -1]], columns=["A", "B"])
713+
tm.assert_frame_equal(result, expected, check_dtype=False)
714+
715+
result = df_len0.sub(df["A"], axis=0, fill_value=3)
716+
expected = DataFrame([[2, 2], [0, 0]], columns=["A", "B"])
717+
tm.assert_frame_equal(result, expected, check_dtype=False)
718+
719+
result = df_len0.sub(df["A"], axis=1, fill_value=3)
720+
expected = DataFrame([], columns=["A", "B", 0, 1])
721+
tm.assert_frame_equal(result, expected, check_dtype=False)
712722

713723
def test_flex_add_scalar_fill_value(self):
714724
# GH#12723

0 commit comments

Comments
 (0)