From e110912bdefa2f3262abceb368f153cbe5739d9b Mon Sep 17 00:00:00 2001 From: Luke Manley Date: Wed, 4 Jan 2023 17:45:34 -0500 Subject: [PATCH 1/2] CLN: MultiIndex._union --- pandas/core/indexes/multi.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 48cf6000d100d..9c54f2be5b4ed 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -3503,12 +3503,8 @@ def equal_levels(self, other: MultiIndex) -> bool: def _union(self, other, sort) -> MultiIndex: other, result_names = self._convert_can_do_setop(other) - if ( - any(-1 in code for code in self.codes) - and any(-1 in code for code in other.codes) - or other.has_duplicates - ): - # This is only necessary if both sides have nans or other has dups, + if other.has_duplicates: + # This is only necessary if other has dups, # otherwise difference is faster result = super()._union(other, sort) From 49bc10ee90f4aec9e586ed6979ecf93a6aff55c9 Mon Sep 17 00:00:00 2001 From: Luke Manley Date: Thu, 5 Jan 2023 07:59:16 -0500 Subject: [PATCH 2/2] remove test for warning --- pandas/core/indexes/multi.py | 2 +- pandas/tests/frame/methods/test_combine_first.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 9c54f2be5b4ed..3d149eccc746b 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -3504,7 +3504,7 @@ def equal_levels(self, other: MultiIndex) -> bool: def _union(self, other, sort) -> MultiIndex: other, result_names = self._convert_can_do_setop(other) if other.has_duplicates: - # This is only necessary if other has dups, + # This is only necessary if other has dupes, # otherwise difference is faster result = super()._union(other, sort) diff --git a/pandas/tests/frame/methods/test_combine_first.py b/pandas/tests/frame/methods/test_combine_first.py index ad6122501bc19..f7da28a43590d 100644 --- a/pandas/tests/frame/methods/test_combine_first.py +++ b/pandas/tests/frame/methods/test_combine_first.py @@ -398,11 +398,7 @@ def test_combine_first_string_dtype_only_na(self, nullable_string_dtype): pa_version_under7p0 and nullable_string_dtype == "string[pyarrow]", ): df2.set_index(["a", "b"], inplace=True) - with tm.maybe_produces_warning( - PerformanceWarning, - pa_version_under7p0 and nullable_string_dtype == "string[pyarrow]", - ): - result = df.combine_first(df2) + result = df.combine_first(df2) with tm.maybe_produces_warning( PerformanceWarning, pa_version_under7p0 and nullable_string_dtype == "string[pyarrow]",