From b5290b0f6afc4bd847a7d577c85b9dd3f608f5dc Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:36:57 -0800 Subject: [PATCH] BUG: Index.join with different names doesn't return None name --- doc/source/whatsnew/v3.0.0.rst | 9 ++++----- pandas/core/indexes/base.py | 2 ++ pandas/tests/indexes/numeric/test_join.py | 9 +++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 950082f9281c5..acf2a0068af8e 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -116,9 +116,6 @@ Performance improvements Bug fixes ~~~~~~~~~ -- Fixed bug in :meth:`DataFrame.join` inconsistently setting result index name (:issue:`55815`) -- Fixed bug in :meth:`Series.diff` allowing non-integer values for the ``periods`` argument. (:issue:`56607`) -- Categorical ^^^^^^^^^^^ @@ -197,8 +194,8 @@ Groupby/resample/rolling Reshaping ^^^^^^^^^ -- -- +- Bug in :meth:`DataFrame.join` inconsistently setting result index name (:issue:`55815`) +- Bug in :meth:`Index.join` where different :class:`Index` with different ``name`` s would not return an :class:`Index` with ``name=None`` (:issue:`57065`) Sparse ^^^^^^ @@ -218,6 +215,8 @@ Styler Other ^^^^^ - Bug in :meth:`DataFrame.where` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`) +- Bug in :meth:`Series.diff` allowing non-integer values for the ``periods`` argument. (:issue:`56607`) + .. ***DO NOT USE THIS SECTION*** diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index bf20525e2c7fd..53ea06a81040b 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4834,6 +4834,8 @@ def _join_non_unique( else: join_index = self.take(left_idx) + join_index.name = ops.get_op_result_name(self, other) + if how == "outer": mask = left_idx == -1 if mask.any(): diff --git a/pandas/tests/indexes/numeric/test_join.py b/pandas/tests/indexes/numeric/test_join.py index 4737af987a04e..7b065d894c686 100644 --- a/pandas/tests/indexes/numeric/test_join.py +++ b/pandas/tests/indexes/numeric/test_join.py @@ -366,3 +366,12 @@ def test_join_outer(self, index_large): tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) + + +def test_join_differing_names_none(): + # GH 57065 + idx1 = Index([1, 1, 2, 3, 4, 4], name="a") + idx2 = Index([2, 5, 3, 4], name="b") + result = idx1.join(idx2) + expected = Index([1, 1, 2, 3, 4, 4]) + tm.assert_index_equal(result, expected)