Skip to content

Commit a77be85

Browse files
authored
Deprecate joining over a different number of levels (#40993)
1 parent f656217 commit a77be85

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ Deprecations
601601
- Deprecated :meth:`.Styler.set_na_rep` and :meth:`.Styler.set_precision` in favour of :meth:`.Styler.format` with ``na_rep`` and ``precision`` as existing and new input arguments respectively (:issue:`40134`, :issue:`40425`)
602602
- Deprecated allowing partial failure in :meth:`Series.transform` and :meth:`DataFrame.transform` when ``func`` is list-like or dict-like and raises anything but ``TypeError``; ``func`` raising anything but a ``TypeError`` will raise in a future version (:issue:`40211`)
603603
- Deprecated support for ``np.ma.mrecords.MaskedRecords`` in the :class:`DataFrame` constructor, pass ``{name: data[name] for name in data.dtype.names}`` instead (:issue:`40363`)
604+
- Deprecated using :func:`merge` or :func:`join` on a different number of levels (:issue:`34862`)
604605
- Deprecated the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`)
605606
- Deprecated the ``level`` keyword for :class:`DataFrame` and :class:`Series` aggregations; use groupby instead (:issue:`39983`)
606607
- Deprecated :func:`merge` producing duplicated columns through the ``suffixes`` keyword and already existing columns (:issue:`22818`)

pandas/core/reshape/merge.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,11 @@ def __init__(
669669
# warn user when merging between different levels
670670
if _left.columns.nlevels != _right.columns.nlevels:
671671
msg = (
672-
"merging between different levels can give an unintended "
673-
f"result ({left.columns.nlevels} levels on the left,"
672+
"merging between different levels is deprecated and will be removed "
673+
f"in a future version. ({left.columns.nlevels} levels on the left,"
674674
f"{right.columns.nlevels} on the right)"
675675
)
676-
warnings.warn(msg, UserWarning)
676+
warnings.warn(msg, FutureWarning, stacklevel=3)
677677

678678
self._validate_specification()
679679

pandas/tests/frame/methods/test_join.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,14 @@ def test_merge_join_different_levels(self):
338338
# merge
339339
columns = ["a", "b", ("c", "c1")]
340340
expected = DataFrame(columns=columns, data=[[1, 11, 33], [0, 22, 44]])
341-
with tm.assert_produces_warning(UserWarning):
341+
with tm.assert_produces_warning(FutureWarning):
342342
result = pd.merge(df1, df2, on="a")
343343
tm.assert_frame_equal(result, expected)
344344

345345
# join, see discussion in GH#12219
346346
columns = ["a", "b", ("a", ""), ("c", "c1")]
347347
expected = DataFrame(columns=columns, data=[[1, 11, 0, 44], [0, 22, 1, 33]])
348-
with tm.assert_produces_warning(UserWarning):
348+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
349349
result = df1.join(df2, on="a")
350350
tm.assert_frame_equal(result, expected)
351351

pandas/tests/reshape/merge/test_join.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_join_hierarchical_mixed(self):
417417
other_df = DataFrame([(1, 2, 3), (7, 10, 6)], columns=["a", "b", "d"])
418418
other_df.set_index("a", inplace=True)
419419
# GH 9455, 12219
420-
with tm.assert_produces_warning(UserWarning):
420+
with tm.assert_produces_warning(FutureWarning):
421421
result = merge(new_df, other_df, left_index=True, right_index=True)
422422
assert ("b", "mean") in result
423423
assert "b" in result

0 commit comments

Comments
 (0)