Skip to content

Commit c93e69a

Browse files
committed
fix for df.eval can't concatenate string column and string via +
1 parent ea7ff0e commit c93e69a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/core/computation/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def return_type(self):
238238
@property
239239
def has_invalid_return_type(self) -> bool:
240240
types = self.operand_types
241-
obj_dtype_set = frozenset([np.dtype("object")])
241+
obj_dtype_set = frozenset([np.dtype("object"), str])
242242
return self.return_type == object and types - obj_dtype_set
243243

244244
@property

pandas/tests/computation/test_eval.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,13 @@ def test_eval_keep_name(self, engine, parser):
743743
expected = Series([4, 30, 56], name="a")
744744
tm.assert_series_equal(expected, res)
745745

746+
def test_obj_str_addition(self, engine, parser):
747+
# GH 47734
748+
df = DataFrame({"a": ["a", "b"]})
749+
res = df.eval("a + 'a'", engine="python")
750+
expected = Series(["aa", "ba"], name="a")
751+
tm.assert_series_equal(expected, res)
752+
746753
def test_eval_unmatching_names(self, engine, parser):
747754
variable_name = Series([42], name="series_name")
748755
res = pd.eval("variable_name + 0", engine=engine, parser=parser)

0 commit comments

Comments
 (0)