From c9c950627205a7c1a9e180ffceb6f5875125d407 Mon Sep 17 00:00:00 2001 From: jackgoldsmith4 Date: Sun, 12 Jun 2022 20:17:14 -0400 Subject: [PATCH 1/7] multiindex lexsort depth test --- pandas/tests/indexes/multi/test_setops.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/tests/indexes/multi/test_setops.py b/pandas/tests/indexes/multi/test_setops.py index 5d1efea657426..d14f5af6e9d1e 100644 --- a/pandas/tests/indexes/multi/test_setops.py +++ b/pandas/tests/indexes/multi/test_setops.py @@ -544,3 +544,20 @@ def test_union_duplicates(index, request): result = mi2.union(mi1) tm.assert_index_equal(result, mi2.sort_values()) + +@pytest.mark.parametrize( + "levels1, levels2, codes1, codes2, names", + [ + ([['2018', 'a', 'c', 'e', 'num', 'oan', 'vol'], [1970, '']], + [['e', 'num', 'oan', 'vol', 'year'], ['']], [[3, 6, 4, ], [1, 1, 1]], + [[3, 1, 4, 1, 0], [0, 0, 0, 0, 0]], ['variable', 'cit_year']), + ], +) +def test_intersection_lexsort_depth(levels1, levels2, codes1, codes2, names): + # GH#25169 + mi1 = MultiIndex(levels=levels1, codes=codes2, names=names) + mi2 = MultiIndex(levels=levels2, codes=codes2, names=names) + mi_int = mi1.intersection(mi2) + expected = 0 + + assert mi_int.lexsort_depth.equals(expected) From 70a17e1467addbb251c82d424651bd21270a4e04 Mon Sep 17 00:00:00 2001 From: jackgoldsmith4 Date: Sun, 19 Jun 2022 09:59:06 -0400 Subject: [PATCH 2/7] add periodindex loc test --- pandas/tests/indexing/test_loc.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 9b1cb69cc33ad..c52f28329ac3a 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2878,6 +2878,13 @@ def test_loc_set_int_dtype(): tm.assert_frame_equal(df, expected) +def test_loc_periodindex_3_levels(): + # GH#24091 + p_index = PeriodIndex(["20181101 1100", "20181101 1200", "20181102 1300", "20181102 1400"], name='datetime', freq="B") + mi_series = DataFrame([["A", "B", 1.0], ["A", "C", 2.0], ["Z", "Q", 3.0], ["W", "F", 4.0]], index=p_index, columns=["ONE", "TWO", "VALUES"]) + mi_series = mi_series.set_index(["ONE", "TWO"], append=True)["VALUES"] + assert mi_series.loc[(p_index[0], "A", "B")] == 1.0 + class TestLocSeries: @pytest.mark.parametrize("val,expected", [(2**63 - 1, 3), (2**63, 4)]) def test_loc_uint64(self, val, expected): From 810b0aa3e5609c30166166a13da8b06e5ee314ea Mon Sep 17 00:00:00 2001 From: jackgoldsmith4 Date: Sun, 19 Jun 2022 14:03:00 +0000 Subject: [PATCH 3/7] import --- pandas/tests/indexing/test_loc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index c52f28329ac3a..06132ae2f2cbe 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -24,6 +24,7 @@ IndexSlice, MultiIndex, Period, + PeriodIndex, Series, SparseDtype, Timedelta, @@ -2885,6 +2886,7 @@ def test_loc_periodindex_3_levels(): mi_series = mi_series.set_index(["ONE", "TWO"], append=True)["VALUES"] assert mi_series.loc[(p_index[0], "A", "B")] == 1.0 + class TestLocSeries: @pytest.mark.parametrize("val,expected", [(2**63 - 1, 3), (2**63, 4)]) def test_loc_uint64(self, val, expected): From 67839dffd813ee090e39d2d946d52062cf0e737f Mon Sep 17 00:00:00 2001 From: jackgoldsmith4 Date: Sun, 19 Jun 2022 10:06:44 -0400 Subject: [PATCH 4/7] pep --- pandas/tests/indexes/multi/test_setops.py | 5 +++-- pandas/tests/indexing/test_loc.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexes/multi/test_setops.py b/pandas/tests/indexes/multi/test_setops.py index d14f5af6e9d1e..1b281a810f88b 100644 --- a/pandas/tests/indexes/multi/test_setops.py +++ b/pandas/tests/indexes/multi/test_setops.py @@ -545,12 +545,13 @@ def test_union_duplicates(index, request): result = mi2.union(mi1) tm.assert_index_equal(result, mi2.sort_values()) + @pytest.mark.parametrize( "levels1, levels2, codes1, codes2, names", [ ([['2018', 'a', 'c', 'e', 'num', 'oan', 'vol'], [1970, '']], - [['e', 'num', 'oan', 'vol', 'year'], ['']], [[3, 6, 4, ], [1, 1, 1]], - [[3, 1, 4, 1, 0], [0, 0, 0, 0, 0]], ['variable', 'cit_year']), + [['e', 'num', 'oan', 'vol', 'year'], ['']], [[3, 6, 4, ], [1, 1, 1]], + [[3, 1, 4, 1, 0], [0, 0, 0, 0, 0]], ['variable', 'cit_year']), ], ) def test_intersection_lexsort_depth(levels1, levels2, codes1, codes2, names): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 06132ae2f2cbe..fc7717132cacd 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2881,8 +2881,11 @@ def test_loc_set_int_dtype(): def test_loc_periodindex_3_levels(): # GH#24091 - p_index = PeriodIndex(["20181101 1100", "20181101 1200", "20181102 1300", "20181102 1400"], name='datetime', freq="B") - mi_series = DataFrame([["A", "B", 1.0], ["A", "C", 2.0], ["Z", "Q", 3.0], ["W", "F", 4.0]], index=p_index, columns=["ONE", "TWO", "VALUES"]) + p_index = PeriodIndex(["20181101 1100", "20181101 1200", "20181102 1300", + "20181102 1400"], name='datetime', freq="B") + mi_series = DataFrame([["A", "B", 1.0], ["A", "C", 2.0], ["Z", "Q", 3.0], + ["W", "F", 4.0]], index=p_index, + columns=["ONE", "TWO", "VALUES"]) mi_series = mi_series.set_index(["ONE", "TWO"], append=True)["VALUES"] assert mi_series.loc[(p_index[0], "A", "B")] == 1.0 From 9b70d1e58c48e0d40637b900ebbc5ca2dca6cdf9 Mon Sep 17 00:00:00 2001 From: jackgoldsmith4 Date: Sun, 19 Jun 2022 14:40:12 +0000 Subject: [PATCH 5/7] Fixes from pre-commit [automated commit] --- pandas/tests/indexes/multi/test_setops.py | 17 ++++++++++++++--- pandas/tests/indexing/test_loc.py | 15 ++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/pandas/tests/indexes/multi/test_setops.py b/pandas/tests/indexes/multi/test_setops.py index 1b281a810f88b..100b6bc3c5c82 100644 --- a/pandas/tests/indexes/multi/test_setops.py +++ b/pandas/tests/indexes/multi/test_setops.py @@ -549,9 +549,20 @@ def test_union_duplicates(index, request): @pytest.mark.parametrize( "levels1, levels2, codes1, codes2, names", [ - ([['2018', 'a', 'c', 'e', 'num', 'oan', 'vol'], [1970, '']], - [['e', 'num', 'oan', 'vol', 'year'], ['']], [[3, 6, 4, ], [1, 1, 1]], - [[3, 1, 4, 1, 0], [0, 0, 0, 0, 0]], ['variable', 'cit_year']), + ( + [["2018", "a", "c", "e", "num", "oan", "vol"], [1970, ""]], + [["e", "num", "oan", "vol", "year"], [""]], + [ + [ + 3, + 6, + 4, + ], + [1, 1, 1], + ], + [[3, 1, 4, 1, 0], [0, 0, 0, 0, 0]], + ["variable", "cit_year"], + ), ], ) def test_intersection_lexsort_depth(levels1, levels2, codes1, codes2, names): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index fc7717132cacd..33dcfcdc294ae 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2881,11 +2881,16 @@ def test_loc_set_int_dtype(): def test_loc_periodindex_3_levels(): # GH#24091 - p_index = PeriodIndex(["20181101 1100", "20181101 1200", "20181102 1300", - "20181102 1400"], name='datetime', freq="B") - mi_series = DataFrame([["A", "B", 1.0], ["A", "C", 2.0], ["Z", "Q", 3.0], - ["W", "F", 4.0]], index=p_index, - columns=["ONE", "TWO", "VALUES"]) + p_index = PeriodIndex( + ["20181101 1100", "20181101 1200", "20181102 1300", "20181102 1400"], + name="datetime", + freq="B", + ) + mi_series = DataFrame( + [["A", "B", 1.0], ["A", "C", 2.0], ["Z", "Q", 3.0], ["W", "F", 4.0]], + index=p_index, + columns=["ONE", "TWO", "VALUES"], + ) mi_series = mi_series.set_index(["ONE", "TWO"], append=True)["VALUES"] assert mi_series.loc[(p_index[0], "A", "B")] == 1.0 From 7d0d94489188bf6ec150f23dcdd7fb40766d3a2e Mon Sep 17 00:00:00 2001 From: jackgoldsmith4 Date: Sun, 19 Jun 2022 14:59:08 -0400 Subject: [PATCH 6/7] fix assert --- pandas/tests/indexes/multi/test_setops.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/indexes/multi/test_setops.py b/pandas/tests/indexes/multi/test_setops.py index 100b6bc3c5c82..d339f0c4c683d 100644 --- a/pandas/tests/indexes/multi/test_setops.py +++ b/pandas/tests/indexes/multi/test_setops.py @@ -570,6 +570,5 @@ def test_intersection_lexsort_depth(levels1, levels2, codes1, codes2, names): mi1 = MultiIndex(levels=levels1, codes=codes2, names=names) mi2 = MultiIndex(levels=levels2, codes=codes2, names=names) mi_int = mi1.intersection(mi2) - expected = 0 - assert mi_int.lexsort_depth.equals(expected) + assert mi_int.lexsort_depth == 0 From 579141748f18db78ace5f37b4ea71986c3f2e981 Mon Sep 17 00:00:00 2001 From: jackgoldsmith4 Date: Tue, 21 Jun 2022 13:47:58 +0000 Subject: [PATCH 7/7] fewer elements --- pandas/tests/indexes/multi/test_setops.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/pandas/tests/indexes/multi/test_setops.py b/pandas/tests/indexes/multi/test_setops.py index d339f0c4c683d..57c4af1a0fe1c 100644 --- a/pandas/tests/indexes/multi/test_setops.py +++ b/pandas/tests/indexes/multi/test_setops.py @@ -550,24 +550,17 @@ def test_union_duplicates(index, request): "levels1, levels2, codes1, codes2, names", [ ( - [["2018", "a", "c", "e", "num", "oan", "vol"], [1970, ""]], - [["e", "num", "oan", "vol", "year"], [""]], - [ - [ - 3, - 6, - 4, - ], - [1, 1, 1], - ], - [[3, 1, 4, 1, 0], [0, 0, 0, 0, 0]], - ["variable", "cit_year"], + [["a", "b", "c"], [0, ""]], + [["c", "d", "b"], [""]], + [[0, 1, 2], [1, 1, 1]], + [[0, 1, 2], [0, 0, 0]], + ["name1", "name2"], ), ], ) def test_intersection_lexsort_depth(levels1, levels2, codes1, codes2, names): # GH#25169 - mi1 = MultiIndex(levels=levels1, codes=codes2, names=names) + mi1 = MultiIndex(levels=levels1, codes=codes1, names=names) mi2 = MultiIndex(levels=levels2, codes=codes2, names=names) mi_int = mi1.intersection(mi2)