diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 0e4a64d7e6c5f..a904f4d9fbe13 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -145,10 +145,12 @@ def merge( indicator: str | bool = False, validate: str | None = None, ) -> DataFrame: + left_df = _validate_operand(left) + right_df = _validate_operand(right) if how == "cross": return _cross_merge( - left, - right, + left_df, + right_df, on=on, left_on=left_on, right_on=right_on, @@ -162,8 +164,8 @@ def merge( ) else: op = _MergeOperation( - left, - right, + left_df, + right_df, how=how, on=on, left_on=left_on, @@ -179,8 +181,8 @@ def merge( def _cross_merge( - left: DataFrame | Series, - right: DataFrame | Series, + left: DataFrame, + right: DataFrame, on: IndexLabel | None = None, left_on: IndexLabel | None = None, right_on: IndexLabel | None = None, diff --git a/pandas/tests/reshape/merge/test_merge_cross.py b/pandas/tests/reshape/merge/test_merge_cross.py index 7e14b515836cf..14f9036e43fce 100644 --- a/pandas/tests/reshape/merge/test_merge_cross.py +++ b/pandas/tests/reshape/merge/test_merge_cross.py @@ -1,6 +1,9 @@ import pytest -from pandas import DataFrame +from pandas import ( + DataFrame, + Series, +) import pandas._testing as tm from pandas.core.reshape.merge import ( MergeError, @@ -96,3 +99,13 @@ def test_join_cross_error_reporting(): ) with pytest.raises(MergeError, match=msg): left.join(right, how="cross", on="a") + + +def test_merge_cross_series(): + # GH#54055 + ls = Series([1, 2, 3, 4], index=[1, 2, 3, 4], name="left") + rs = Series([3, 4, 5, 6], index=[3, 4, 5, 6], name="right") + res = merge(ls, rs, how="cross") + + expected = merge(ls.to_frame(), rs.to_frame(), how="cross") + tm.assert_frame_equal(res, expected)