Skip to content

REGR: fix error caused by deprecation warning in pd.merge when joining two Series #47946

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 7 commits into from
Aug 19, 2022
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Fixed regressions
- Fixed regression in :meth:`DataFrame.loc` not updating the cache correctly after values were set (:issue:`47867`)
- Fixed regression in :meth:`DataFrame.loc` not aligning index in some cases when setting a :class:`DataFrame` (:issue:`47578`)
- Fixed regression in setting ``None`` or non-string value into a ``string``-dtype Series using a mask (:issue:`47628`)
- Fixed regression in :func:`merge` throwing an error when passing a :class:`Series` with a multi-level name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is no issue then the PR number should be added as the issue instead

(imo that should never happen though as an issue should always be raised to document the issue. there are many reasons to do this, help users find it, avoid duplicate issues, allow proper triage and give others an opportunity for discussion, and keep these out of the PR discussion as appears to have happen here)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also sometimes PRs go stale so the discussion in those cases is effectively lost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks for pointing out Simon!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the sentiment. The only reason that I didn't create an issue in the first place was that I thought the bug happened because of a typo and that this PR should be straightforward. Aside from this, I want to point out two things:

  1. Now that you've decided to reference the PR instead of the issue, you may want to add the base path of Github PRs to sphinx.ext.extlinks. From what I'm seeing, only the base path of issues is provided in the configuration file.
  2. FYI, I ran into this bug when I was applying a complex function to a Series after a multi-level GroupBy.

Copy link
Member

@jorisvandenbossche jorisvandenbossche Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Now that you've decided to reference the PR instead of the issue, you may want to add the base path of Github PRs to sphinx.ext.extlinks. From what I'm seeing, only the base path of issues is provided in the configuration file.

GitHub itself handles those links fine. For example the link for this PR (#47946), also works (redirects) if used with "issues": #47946

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh I see. Thanks @jorisvandenbossche !

- Fixed regression in :meth:`DataFrame.eval` creating a copy when updating inplace (:issue:`47449`)
-

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,8 @@ def __init__(
if _left.columns.nlevels != _right.columns.nlevels:
msg = (
"merging between different levels is deprecated and will be removed "
f"in a future version. ({left.columns.nlevels} levels on the left, "
f"{right.columns.nlevels} on the right)"
f"in a future version. ({_left.columns.nlevels} levels on the left, "
f"{_right.columns.nlevels} on the right)"
)
# stacklevel chosen to be correct when this is reached via pd.merge
# (and not DataFrame.join)
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/reshape/merge/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,26 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm):
)


def test_merge_series_multilevel():
# GH#47946
a = DataFrame(
{"A": [1, 2, 3, 4]},
index=MultiIndex.from_product([["a", "b"], [0, 1]], names=["outer", "inner"]),
)
b = Series(
[1, 2, 3, 4],
index=MultiIndex.from_product([["a", "b"], [1, 2]], names=["outer", "inner"]),
name=("B", "C"),
)
expected = DataFrame(
{"A": [2, 4], ("B", "C"): [1, 3]},
index=MultiIndex.from_product([["a", "b"], [1]], names=["outer", "inner"]),
)
with tm.assert_produces_warning(FutureWarning):
result = merge(a, b, on=["outer", "inner"])
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"col1, col2, kwargs, expected_cols",
[
Expand Down