Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ Other Deprecations
- Deprecated allowing ``fill_value`` that cannot be held in the original dtype (excepting NA values for integer and bool dtypes) in :meth:`Series.shift` and :meth:`DataFrame.shift` (:issue:`53802`)
- Deprecated backward-compatibility behavior for :meth:`DataFrame.select_dtypes` matching "str" dtype when ``np.object_`` is specified (:issue:`61916`)
- Deprecated option "future.no_silent_downcasting", as it is no longer used. In a future version accessing this option will raise (:issue:`59502`)
- Deprecated passing a :class:`Series` to :meth:`Index.join`, pass ``Index.join(other.index)`` instead (:issue:`62897`)
Copy link
Member

Choose a reason for hiding this comment

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

can you update this line to reflect that it is any non-Index and not just Series

- Deprecated silent casting of non-datetime 'other' to datetime in :meth:`Series.combine_first` (:issue:`62931`)
- 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`)
- Deprecated the 'inplace' keyword from :meth:`Resampler.interpolate`, as passing ``True`` raises ``AttributeError`` (:issue:`58690`)
Expand Down
10 changes: 10 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from pandas.errors import (
DuplicateLabelError,
InvalidIndexError,
Pandas4Warning,
)
from pandas.util._decorators import (
Appender,
Expand Down Expand Up @@ -4426,6 +4427,15 @@ def join(
(Index([1, 2, 3, 4, 5, 6], dtype='int64'),
array([ 0, 1, 2, -1, -1, -1]), array([-1, -1, -1, 0, 1, 2]))
"""
if not isinstance(other, Index):
warnings.warn(
f"Passing a Series to {type(self).__name__}.join is deprecated "
Copy link
Member

Choose a reason for hiding this comment

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

This message will only be correct for a Series other, but the condition is only for non-Index. can you either make the message more general or condition more specific

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 appreciate the input! Should I drop support for just Series (since that's what the issue references), or for all non-Index types (to be consistent with the signature that states other: Index)?

I'll take the specific option (isinstance(other, Series)), unless you prefer the general option?

Copy link
Member

Choose a reason for hiding this comment

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

id deprecate for all non-Index objects.

"and will raise in a future version. "
"Pass Index.join(other.index) instead.",
Pandas4Warning,
stacklevel=find_stack_level(),
)

other = ensure_index(other)
sort = sort or how == "outer"

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest

from pandas.compat import IS64
from pandas.errors import Pandas4Warning

from pandas.core.dtypes.common import (
is_integer_dtype,
Expand Down Expand Up @@ -523,3 +524,11 @@ def test_to_frame_name_tuple_multiindex():
result = idx.to_frame(name=(1, 2))
expected = pd.DataFrame([1], columns=MultiIndex.from_arrays([[1], [2]]), index=idx)
tm.assert_frame_equal(result, expected)


def test_join_series_deprecated():
# GH#62897
idx = pd.Index([1, 2])
ser = pd.Series([1, 2, 2])
with tm.assert_produces_warning(Pandas4Warning, match="Passing a Series"):
idx.join(ser)
Loading