Skip to content

Commit ede9a18

Browse files
DEPR: deprecate passing Series to Index.join (#62948)
1 parent efe1a5c commit ede9a18

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ Other Deprecations
740740
- Deprecated allowing strings representing full dates in :meth:`DataFrame.at_time` and :meth:`Series.at_time` (:issue:`50839`)
741741
- Deprecated backward-compatibility behavior for :meth:`DataFrame.select_dtypes` matching "str" dtype when ``np.object_`` is specified (:issue:`61916`)
742742
- Deprecated option "future.no_silent_downcasting", as it is no longer used. In a future version accessing this option will raise (:issue:`59502`)
743+
- Deprecated passing non-Index types to :meth:`Index.join`; explicitly convert to Index first (:issue:`62897`)
743744
- Deprecated silent casting of non-datetime 'other' to datetime in :meth:`Series.combine_first` (:issue:`62931`)
744745
- Deprecated slicing on a :class:`Series` or :class:`DataFrame` with a :class:`DatetimeIndex` using a ``datetime.date`` object, explicitly cast to :class:`Timestamp` instead (:issue:`35830`)
745746
- Deprecated support for the Dataframe Interchange Protocol (:issue:`56732`)

pandas/core/indexes/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
from pandas.errors import (
7070
DuplicateLabelError,
7171
InvalidIndexError,
72+
Pandas4Warning,
7273
)
7374
from pandas.util._decorators import (
7475
Appender,
@@ -4426,6 +4427,15 @@ def join(
44264427
(Index([1, 2, 3, 4, 5, 6], dtype='int64'),
44274428
array([ 0, 1, 2, -1, -1, -1]), array([-1, -1, -1, 0, 1, 2]))
44284429
"""
4430+
if not isinstance(other, Index):
4431+
warnings.warn(
4432+
f"Passing {type(other).__name__} to {type(self).__name__}.join "
4433+
"is deprecated and will raise in a future version. "
4434+
"Pass an Index instead.",
4435+
Pandas4Warning,
4436+
stacklevel=find_stack_level(),
4437+
)
4438+
44294439
other = ensure_index(other)
44304440
sort = sort or how == "outer"
44314441

pandas/tests/indexes/test_common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import pytest
1515

1616
from pandas.compat import IS64
17+
from pandas.errors import Pandas4Warning
1718

1819
from pandas.core.dtypes.common import (
1920
is_integer_dtype,
@@ -523,3 +524,13 @@ def test_to_frame_name_tuple_multiindex():
523524
result = idx.to_frame(name=(1, 2))
524525
expected = pd.DataFrame([1], columns=MultiIndex.from_arrays([[1], [2]]), index=idx)
525526
tm.assert_frame_equal(result, expected)
527+
528+
529+
def test_join_series_deprecated():
530+
# GH#62897
531+
idx = pd.Index([1, 2])
532+
ser = pd.Series([1, 2, 2])
533+
with tm.assert_produces_warning(
534+
Pandas4Warning, match="Passing .* to .* is deprecated"
535+
):
536+
idx.join(ser)

0 commit comments

Comments
 (0)