Skip to content

BUG: merge cross with Series #54087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -162,8 +164,8 @@ def merge(
)
else:
op = _MergeOperation(
left,
right,
left_df,
right_df,
how=how,
on=on,
left_on=left_on,
Expand All @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion pandas/tests/reshape/merge/test_merge_cross.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)