From c0fe2e0670eafcd8505603e8eebf8e7a856cde69 Mon Sep 17 00:00:00 2001 From: Tan Tran Date: Sun, 14 Apr 2019 17:30:55 +0700 Subject: [PATCH 1/8] TST GH17347 Create test case for issue GH17347 --- pandas/tests/indexing/test_indexing.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 3cdae198cad31..37394b9da1452 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -622,6 +622,27 @@ def test_index_type_coercion(self): s2 = s.copy() idxr(s2)['0'] = 0 assert s2.index.is_object() + + @pytest.mark.parametrize('idx', [ + Index([1, 1, 3]), + Index(['a', 'a', 'b', 'c', 'c', 'd']), + Index([1, 1, 1, 2, 2, 3]), + Index([1, 1, 2, 3, 1, 2, 3, 3]) + ]) + def test_duplicate_int_indexing(self, idx): + # GH 17347 + s = pd.Series(range(len(idx)), idx) + dup_idx_filter = s.index.duplicated(keep=False) + + # Check if s contains duplicated idx + if not dup_idx_filter.any: + pass + # Find the duplicate indexes + dup_idxes = s[dup_idx_filter].index.unique() + + # Assert the duplicate indexes + for idx in dup_idxes: + assert s[idx].equals(s[[idx]]) class TestMisc(Base): From 312e082283ee8c31ca2ba44423874218daf61911 Mon Sep 17 00:00:00 2001 From: Tan Tran Date: Sun, 14 Apr 2019 18:40:05 +0700 Subject: [PATCH 2/8] TST GH17347 Create test case for issue GH17347 --- pandas/tests/indexing/test_indexing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 37394b9da1452..375e55f6f4435 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -622,7 +622,7 @@ def test_index_type_coercion(self): s2 = s.copy() idxr(s2)['0'] = 0 assert s2.index.is_object() - + @pytest.mark.parametrize('idx', [ Index([1, 1, 3]), Index(['a', 'a', 'b', 'c', 'c', 'd']), @@ -633,7 +633,7 @@ def test_duplicate_int_indexing(self, idx): # GH 17347 s = pd.Series(range(len(idx)), idx) dup_idx_filter = s.index.duplicated(keep=False) - + # Check if s contains duplicated idx if not dup_idx_filter.any: pass From 34c9f859956a9ce152c297fd0ea6e38942ce2528 Mon Sep 17 00:00:00 2001 From: Tan Tran Date: Mon, 15 Apr 2019 01:25:33 +0700 Subject: [PATCH 3/8] simply test case and switch to tm.assert --- pandas/tests/indexing/test_indexing.py | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 375e55f6f4435..8edc4558d21e2 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -623,27 +623,10 @@ def test_index_type_coercion(self): idxr(s2)['0'] = 0 assert s2.index.is_object() - @pytest.mark.parametrize('idx', [ - Index([1, 1, 3]), - Index(['a', 'a', 'b', 'c', 'c', 'd']), - Index([1, 1, 1, 2, 2, 3]), - Index([1, 1, 2, 3, 1, 2, 3, 3]) - ]) - def test_duplicate_int_indexing(self, idx): + def test_duplicate_int_indexing(self): # GH 17347 - s = pd.Series(range(len(idx)), idx) - dup_idx_filter = s.index.duplicated(keep=False) - - # Check if s contains duplicated idx - if not dup_idx_filter.any: - pass - # Find the duplicate indexes - dup_idxes = s[dup_idx_filter].index.unique() - - # Assert the duplicate indexes - for idx in dup_idxes: - assert s[idx].equals(s[[idx]]) - + s = pd.Series(range(3), index=[1, 1, 3]) + tm.assert_series_equal(s[1],s[[1]]) class TestMisc(Base): From f5c2d5498e0aa4d8d4fc39b5e124ef322c3c90c0 Mon Sep 17 00:00:00 2001 From: Tan Tran Date: Mon, 15 Apr 2019 01:58:21 +0700 Subject: [PATCH 4/8] simplify test case and switch to tm.assert --- pandas/tests/indexing/test_indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 8edc4558d21e2..53f5dd7748646 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -626,7 +626,7 @@ def test_index_type_coercion(self): def test_duplicate_int_indexing(self): # GH 17347 s = pd.Series(range(3), index=[1, 1, 3]) - tm.assert_series_equal(s[1],s[[1]]) + tm.assert_series_equal(s[1], s[[1]]) class TestMisc(Base): From 4015bf5401f9c44048d3da54d180b61734457e9e Mon Sep 17 00:00:00 2001 From: Tan Tran Date: Mon, 15 Apr 2019 09:09:17 +0700 Subject: [PATCH 5/8] refractor code and check loc case --- pandas/tests/indexing/test_indexing.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 53f5dd7748646..a302f665e024e 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -626,7 +626,11 @@ def test_index_type_coercion(self): def test_duplicate_int_indexing(self): # GH 17347 s = pd.Series(range(3), index=[1, 1, 3]) - tm.assert_series_equal(s[1], s[[1]]) + expected = s[1] + result = s[[1]] + result2 = s.loc[[1]] + tm.assert_series_equal(result, expected) + tm.assert_series_equal(result2, expected) class TestMisc(Base): From f4ce36f58d8c10a052cc6912295f3d47d6e02c24 Mon Sep 17 00:00:00 2001 From: Tan Tran Date: Mon, 15 Apr 2019 10:53:14 +0700 Subject: [PATCH 6/8] Fix checks_and_docs --- pandas/tests/indexing/test_indexing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index a302f665e024e..1d97d72d18061 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -632,6 +632,7 @@ def test_duplicate_int_indexing(self): tm.assert_series_equal(result, expected) tm.assert_series_equal(result2, expected) + class TestMisc(Base): def test_float_index_to_mixed(self): From ff0fb7ac5d4a8e109a4c01fade4001b927fea539 Mon Sep 17 00:00:00 2001 From: Tan Tran Date: Mon, 15 Apr 2019 23:15:54 +0700 Subject: [PATCH 7/8] refactor code using parametrize --- pandas/tests/indexing/test_indexing.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 1d97d72d18061..7a75c1666efe1 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -243,6 +243,14 @@ def test_dups_fancy_indexing2(self): result = df.loc[[1, 2], ['a', 'b']] tm.assert_frame_equal(result, expected) + @pytest.mark.parametrize('case',[lambda s: s, lambda s: s.loc]) + def test_duplicate_int_indexing(self, case): + # GH 17347 + s = pd.Series(range(3), index=[1, 1, 3]) + expected = s[1] + result = case(s)[[1]] + tm.assert_series_equal(result, expected) + def test_indexing_mixed_frame_bug(self): # GH3492 @@ -623,15 +631,6 @@ def test_index_type_coercion(self): idxr(s2)['0'] = 0 assert s2.index.is_object() - def test_duplicate_int_indexing(self): - # GH 17347 - s = pd.Series(range(3), index=[1, 1, 3]) - expected = s[1] - result = s[[1]] - result2 = s.loc[[1]] - tm.assert_series_equal(result, expected) - tm.assert_series_equal(result2, expected) - class TestMisc(Base): From d25af6161e8df1a388e2bba0f5e0c719e31592bb Mon Sep 17 00:00:00 2001 From: Tan Tran Date: Tue, 16 Apr 2019 00:04:12 +0700 Subject: [PATCH 8/8] fix checks_and_doc --- pandas/tests/indexing/test_indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 7a75c1666efe1..03916ead17dc3 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -243,7 +243,7 @@ def test_dups_fancy_indexing2(self): result = df.loc[[1, 2], ['a', 'b']] tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize('case',[lambda s: s, lambda s: s.loc]) + @pytest.mark.parametrize('case', [lambda s: s, lambda s: s.loc]) def test_duplicate_int_indexing(self, case): # GH 17347 s = pd.Series(range(3), index=[1, 1, 3])