Skip to content

Commit ebbc056

Browse files
author
LAPTOP-8CGF3UCA\Alain Khalil
committed
Implicity convert series to DataFrame before doing the concatenation (pandas-dev#56257)
1 parent 52649ea commit ebbc056

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pandas/core/reshape/concat.py

+4
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ def __init__(
413413
copy: bool = True,
414414
sort: bool = False,
415415
) -> None:
416+
for i in range(len(objs)):
417+
if isinstance(objs[i], ABCSeries):
418+
objs[i] = objs[i].to_frame()
419+
416420
if isinstance(objs, (ABCSeries, ABCDataFrame, str)):
417421
raise TypeError(
418422
"first argument must be an iterable of pandas "

pandas/tests/reshape/concat/test_concat.py

+7
Original file line numberDiff line numberDiff line change
@@ -883,3 +883,10 @@ def test_concat_none_with_timezone_timestamp():
883883
result = concat([df1, df2], ignore_index=True)
884884
expected = DataFrame({"A": [None, pd.Timestamp("1990-12-20 00:00:00+00:00")]})
885885
tm.assert_frame_equal(result, expected)
886+
887+
def test_concat_dataframe_and_series():
888+
df1 = DataFrame({'A': [1, 2], 'B': [3, 4]})
889+
s1 = Series([1, 2], name='A')
890+
result = pd.concat([df1, s1])
891+
expected_result = pd.concat([df1, s1.to_frame()])
892+
assert result.equals(expected_result)

0 commit comments

Comments
 (0)