From 7169e58a606bef11ed7702dc71e2d2fb6e1d1dff Mon Sep 17 00:00:00 2001 From: phofl Date: Sun, 21 Feb 2021 21:50:31 +0100 Subject: [PATCH 1/4] CLN: Remove some duplicated tests and parametrize --- pandas/tests/indexing/test_loc.py | 114 +++++++----------------------- 1 file changed, 26 insertions(+), 88 deletions(-) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index c98666b38b8b8..282fcee8c3499 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -266,7 +266,7 @@ def test_loc_getitem_bool_diff_len(self, index): s = Series([1, 2, 3]) msg = f"Boolean index has wrong length: {len(index)} instead of {len(s)}" with pytest.raises(IndexError, match=msg): - _ = s.loc[index] + s.loc[index] def test_loc_getitem_int_slice(self): # TODO: test something here? @@ -408,7 +408,11 @@ def frame_for_consistency(self): } ) - def test_loc_setitem_consistency(self, frame_for_consistency): + @pytest.mark.parametrize( + "val", + [0, np.array(0, dtype=np.int64), np.array([0, 0, 0, 0, 0], dtype=np.int64)], + ) + def test_loc_setitem_consistency(self, frame_for_consistency, val): # GH 6149 # coerce similarly for setitem and loc when rows have a null-slice expected = DataFrame( @@ -418,15 +422,7 @@ def test_loc_setitem_consistency(self, frame_for_consistency): } ) df = frame_for_consistency.copy() - df.loc[:, "date"] = 0 - tm.assert_frame_equal(df, expected) - - df = frame_for_consistency.copy() - df.loc[:, "date"] = np.array(0, dtype=np.int64) - tm.assert_frame_equal(df, expected) - - df = frame_for_consistency.copy() - df.loc[:, "date"] = np.array([0, 0, 0, 0, 0], dtype=np.int64) + df.loc[:, "date"] = val tm.assert_frame_equal(df, expected) def test_loc_setitem_consistency_dt64_to_str(self, frame_for_consistency): @@ -554,8 +550,6 @@ def test_loc_modify_datetime(self): def test_loc_setitem_frame(self): df = DataFrame(np.random.randn(4, 4), index=list("abcd"), columns=list("ABCD")) - result = df.iloc[0, 0] - df.loc["a", "A"] = 1 result = df.loc["a", "A"] assert result == 1 @@ -762,7 +756,8 @@ def test_loc_coercion(self): result = df.iloc[3:] tm.assert_series_equal(result.dtypes, expected) - def test_setitem_new_key_tz(self): + @pytest.mark.parametrize("indexer", [tm.setitem, tm.loc]) + def test_setitem_new_key_tz(self, indexer): # GH#12862 should not raise on assigning the second value vals = [ pd.to_datetime(42).tz_localize("UTC"), @@ -771,14 +766,8 @@ def test_setitem_new_key_tz(self): expected = Series(vals, index=["foo", "bar"]) ser = Series(dtype=object) - ser["foo"] = vals[0] - ser["bar"] = vals[1] - - tm.assert_series_equal(ser, expected) - - ser = Series(dtype=object) - ser.loc["foo"] = vals[0] - ser.loc["bar"] = vals[1] + indexer(ser)["foo"] = vals[0] + indexer(ser)["bar"] = vals[1] tm.assert_series_equal(ser, expected) @@ -1104,7 +1093,7 @@ def test_loc_getitem_timedelta_0seconds(self): df.index = timedelta_range(start="0s", periods=10, freq="s") expected = df.loc[Timedelta("0s") :, :] result = df.loc["0s":, :] - tm.assert_frame_equal(expected, result) + tm.assert_frame_equal(result, expected) @pytest.mark.parametrize( "val,expected", [(2 ** 63 - 1, Series([1])), (2 ** 63, Series([2]))] @@ -1120,12 +1109,12 @@ def test_loc_getitem_uint64_scalar(self, val, expected): def test_loc_setitem_int_label_with_float64index(self): # note labels are floats ser = Series(["a", "b", "c"], index=[0, 0.5, 1]) - tmp = ser.copy() + expected = ser.copy() ser.loc[1] = "zoo" - tmp.iloc[2] = "zoo" + expected.iloc[2] = "zoo" - tm.assert_series_equal(ser, tmp) + tm.assert_series_equal(ser, expected) @pytest.mark.parametrize( "indexer, expected", @@ -1363,42 +1352,18 @@ def test_frame_loc_getitem_callable(self): res = df.loc[lambda x: x.A > 2] tm.assert_frame_equal(res, df.loc[df.A > 2]) - res = df.loc[lambda x: x.A > 2] - tm.assert_frame_equal(res, df.loc[df.A > 2]) - - res = df.loc[lambda x: x.A > 2] - tm.assert_frame_equal(res, df.loc[df.A > 2]) - - res = df.loc[lambda x: x.A > 2] - tm.assert_frame_equal(res, df.loc[df.A > 2]) - - res = df.loc[lambda x: x.B == "b", :] - tm.assert_frame_equal(res, df.loc[df.B == "b", :]) - res = df.loc[lambda x: x.B == "b", :] tm.assert_frame_equal(res, df.loc[df.B == "b", :]) res = df.loc[lambda x: x.A > 2, lambda x: x.columns == "B"] tm.assert_frame_equal(res, df.loc[df.A > 2, [False, True, False]]) - res = df.loc[lambda x: x.A > 2, lambda x: x.columns == "B"] - tm.assert_frame_equal(res, df.loc[df.A > 2, [False, True, False]]) - - res = df.loc[lambda x: x.A > 2, lambda x: "B"] - tm.assert_series_equal(res, df.loc[df.A > 2, "B"]) - res = df.loc[lambda x: x.A > 2, lambda x: "B"] tm.assert_series_equal(res, df.loc[df.A > 2, "B"]) res = df.loc[lambda x: x.A > 2, lambda x: ["A", "B"]] tm.assert_frame_equal(res, df.loc[df.A > 2, ["A", "B"]]) - res = df.loc[lambda x: x.A > 2, lambda x: ["A", "B"]] - tm.assert_frame_equal(res, df.loc[df.A > 2, ["A", "B"]]) - - res = df.loc[lambda x: x.A == 2, lambda x: ["A", "B"]] - tm.assert_frame_equal(res, df.loc[df.A == 2, ["A", "B"]]) - res = df.loc[lambda x: x.A == 2, lambda x: ["A", "B"]] tm.assert_frame_equal(res, df.loc[df.A == 2, ["A", "B"]]) @@ -1406,9 +1371,6 @@ def test_frame_loc_getitem_callable(self): res = df.loc[lambda x: 1, lambda x: "A"] assert res == df.loc[1, "A"] - res = df.loc[lambda x: 1, lambda x: "A"] - assert res == df.loc[1, "A"] - def test_frame_loc_getitem_callable_mixture(self): # GH#11485 df = DataFrame({"A": [1, 2, 3, 4], "B": list("aabb"), "C": [1, 2, 3, 4]}) @@ -1416,21 +1378,12 @@ def test_frame_loc_getitem_callable_mixture(self): res = df.loc[lambda x: x.A > 2, ["A", "B"]] tm.assert_frame_equal(res, df.loc[df.A > 2, ["A", "B"]]) - res = df.loc[lambda x: x.A > 2, ["A", "B"]] - tm.assert_frame_equal(res, df.loc[df.A > 2, ["A", "B"]]) - - res = df.loc[[2, 3], lambda x: ["A", "B"]] - tm.assert_frame_equal(res, df.loc[[2, 3], ["A", "B"]]) - res = df.loc[[2, 3], lambda x: ["A", "B"]] tm.assert_frame_equal(res, df.loc[[2, 3], ["A", "B"]]) res = df.loc[3, lambda x: ["A", "B"]] tm.assert_series_equal(res, df.loc[3, ["A", "B"]]) - res = df.loc[3, lambda x: ["A", "B"]] - tm.assert_series_equal(res, df.loc[3, ["A", "B"]]) - def test_frame_loc_getitem_callable_labels(self): # GH#11485 df = DataFrame({"X": [1, 2, 3, 4], "Y": list("aabb")}, index=list("ABCD")) @@ -1439,9 +1392,6 @@ def test_frame_loc_getitem_callable_labels(self): res = df.loc[lambda x: ["A", "C"]] tm.assert_frame_equal(res, df.loc[["A", "C"]]) - res = df.loc[lambda x: ["A", "C"]] - tm.assert_frame_equal(res, df.loc[["A", "C"]]) - res = df.loc[lambda x: ["A", "C"], :] tm.assert_frame_equal(res, df.loc[["A", "C"], :]) @@ -1611,16 +1561,14 @@ def test_loc_getitem_label_slice_across_dst(self): expected = 2 assert result == expected - def test_loc_getitem_label_slice_period(self): - ix = pd.period_range(start="2017-01-01", end="2018-01-01", freq="M") - ser = ix.to_series() - result = ser.loc[: ix[-2]] - expected = ser.iloc[:-1] - - tm.assert_series_equal(result, expected) - - def test_loc_getitem_label_slice_timedelta64(self): - ix = timedelta_range(start="1 day", end="2 days", freq="1H") + @pytest.mark.parametrize( + "ix", + [ + pd.period_range(start="2017-01-01", end="2018-01-01", freq="M"), + timedelta_range(start="1 day", end="2 days", freq="1H"), + ], + ) + def test_loc_getitem_label_slice_period(self, ix): ser = ix.to_series() result = ser.loc[: ix[-2]] expected = ser.iloc[:-1] @@ -1716,23 +1664,13 @@ def test_loc_setitem_bool_mask_timedeltaindex(self): ) tm.assert_frame_equal(expected, result) - def test_loc_setitem_mask_with_datetimeindex_tz(self): + @pytest.mark.parametrize("tz", [None, "UTC"]) + def test_loc_setitem_mask_with_datetimeindex_tz(self, tz): # GH#16889 # support .loc with alignment and tz-aware DatetimeIndex mask = np.array([True, False, True, False]) - idx = date_range("20010101", periods=4, tz="UTC") - df = DataFrame({"a": np.arange(4)}, index=idx).astype("float64") - - result = df.copy() - result.loc[mask, :] = df.loc[mask, :] - tm.assert_frame_equal(result, df) - - result = df.copy() - result.loc[mask] = df.loc[mask] - tm.assert_frame_equal(result, df) - - idx = date_range("20010101", periods=4) + idx = date_range("20010101", periods=4, tz=tz) df = DataFrame({"a": np.arange(4)}, index=idx).astype("float64") result = df.copy() From a72660fa347dc2230a4b5befb13354327a166c5a Mon Sep 17 00:00:00 2001 From: phofl Date: Sun, 21 Feb 2021 22:27:03 +0100 Subject: [PATCH 2/4] Clean further --- pandas/tests/indexing/test_floats.py | 30 ++------------------------ pandas/tests/indexing/test_iloc.py | 24 ++++----------------- pandas/tests/indexing/test_indexing.py | 14 +++--------- 3 files changed, 9 insertions(+), 59 deletions(-) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index d1f1db741509f..72db5fede1dc3 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -507,30 +507,22 @@ def test_floating_misc(self): # label based slicing result1 = s[1.0:3.0] result2 = s.loc[1.0:3.0] - result3 = s.loc[1.0:3.0] tm.assert_series_equal(result1, result2) - tm.assert_series_equal(result1, result3) # exact indexing when found result1 = s[5.0] result2 = s.loc[5.0] - result3 = s.loc[5.0] assert result1 == result2 - assert result1 == result3 result1 = s[5] result2 = s.loc[5] - result3 = s.loc[5] assert result1 == result2 - assert result1 == result3 assert s[5.0] == s[5] # value not found (and no fallbacking at all) # scalar integers - with pytest.raises(KeyError, match=r"^4$"): - s.loc[4] with pytest.raises(KeyError, match=r"^4$"): s.loc[4] with pytest.raises(KeyError, match=r"^4$"): @@ -542,13 +534,11 @@ def test_floating_misc(self): for fancy_idx in [[5.0, 0.0], np.array([5.0, 0.0])]: # float tm.assert_series_equal(s[fancy_idx], expected) tm.assert_series_equal(s.loc[fancy_idx], expected) - tm.assert_series_equal(s.loc[fancy_idx], expected) expected = Series([2, 0], index=Index([5, 0], dtype="int64")) for fancy_idx in [[5, 0], np.array([5, 0])]: # int tm.assert_series_equal(s[fancy_idx], expected) tm.assert_series_equal(s.loc[fancy_idx], expected) - tm.assert_series_equal(s.loc[fancy_idx], expected) # all should return the same as we are slicing 'the same' result1 = s.loc[2:5] @@ -568,30 +558,18 @@ def test_floating_misc(self): tm.assert_series_equal(result1, result3) tm.assert_series_equal(result1, result4) - result1 = s.loc[2:5] - result2 = s.loc[2.0:5.0] - result3 = s.loc[2.0:5] - result4 = s.loc[2.1:5] - tm.assert_series_equal(result1, result2) - tm.assert_series_equal(result1, result3) - tm.assert_series_equal(result1, result4) - # combined test result1 = s.loc[2:5] - result2 = s.loc[2:5] - result3 = s[2:5] + result2 = s[2:5] tm.assert_series_equal(result1, result2) - tm.assert_series_equal(result1, result3) # list selection result1 = s[[0.0, 5, 10]] result2 = s.loc[[0.0, 5, 10]] - result3 = s.loc[[0.0, 5, 10]] - result4 = s.iloc[[0, 2, 4]] + result3 = s.iloc[[0, 2, 4]] tm.assert_series_equal(result1, result2) tm.assert_series_equal(result1, result3) - tm.assert_series_equal(result1, result4) with pytest.raises(KeyError, match="with any missing labels"): s[[1.6, 5, 10]] @@ -604,15 +582,11 @@ def test_floating_misc(self): s.loc[[0, 1, 2]] result1 = s.loc[[2.5, 5]] - result2 = s.loc[[2.5, 5]] - tm.assert_series_equal(result1, result2) tm.assert_series_equal(result1, Series([1, 2], index=[2.5, 5.0])) result1 = s[[2.5]] result2 = s.loc[[2.5]] - result3 = s.loc[[2.5]] tm.assert_series_equal(result1, result2) - tm.assert_series_equal(result1, result3) tm.assert_series_equal(result1, Series([1], index=[2.5])) def test_floating_tuples(self): diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index d5e5cabc93b66..f7cb9e3bebdec 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -35,28 +35,12 @@ class TestiLoc(Base): - def test_iloc_getitem_int(self): + @pytest.mark.parametrize("key", [2, -1, [0, 1, 2]]) + def test_iloc_getitem_int(self, key): # integer self.check_result( "iloc", - 2, - typs=["labels", "mixed", "ts", "floats", "empty"], - fails=IndexError, - ) - - def test_iloc_getitem_neg_int(self): - # neg integer - self.check_result( - "iloc", - -1, - typs=["labels", "mixed", "ts", "floats", "empty"], - fails=IndexError, - ) - - def test_iloc_getitem_list_int(self): - self.check_result( - "iloc", - [0, 1, 2], + key, typs=["labels", "mixed", "ts", "floats", "empty"], fails=IndexError, ) @@ -371,7 +355,7 @@ def test_iloc_getitem_bool_diff_len(self, index): s = Series([1, 2, 3]) msg = f"Boolean index has wrong length: {len(index)} instead of {len(s)}" with pytest.raises(IndexError, match=msg): - _ = s.iloc[index] + s.iloc[index] def test_iloc_getitem_slice(self): df = DataFrame( diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index aec12f4cedcea..34f7ec9418028 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -266,14 +266,11 @@ def test_dups_fancy_indexing_only_missing_label(self): # ToDo: check_index_type can be True after GH 11497 - def test_dups_fancy_indexing_missing_label(self): + @pytest.mark.parametrize("vals", [[0, 1, 2], list("abc")]) + def test_dups_fancy_indexing_missing_label(self, vals): # GH 4619; duplicate indexer with missing label - df = DataFrame({"A": [0, 1, 2]}) - with pytest.raises(KeyError, match="with any missing labels"): - df.loc[[0, 8, 0]] - - df = DataFrame({"A": list("abc")}) + df = DataFrame({"A": vals}) with pytest.raises(KeyError, match="with any missing labels"): df.loc[[0, 8, 0]] @@ -455,9 +452,6 @@ def test_multi_assign(self): df2.loc[mask, cols] = dft.loc[mask, cols] tm.assert_frame_equal(df2, expected) - df2.loc[mask, cols] = dft.loc[mask, cols] - tm.assert_frame_equal(df2, expected) - # with an ndarray on rhs # coerces to float64 because values has float64 dtype # GH 14001 @@ -472,8 +466,6 @@ def test_multi_assign(self): df2 = df.copy() df2.loc[mask, cols] = dft.loc[mask, cols].values tm.assert_frame_equal(df2, expected) - df2.loc[mask, cols] = dft.loc[mask, cols].values - tm.assert_frame_equal(df2, expected) def test_multi_assign_broadcasting_rhs(self): # broadcasting on the rhs is required From 3bc6ad37f236d31d30f12c5e006a5b6661880511 Mon Sep 17 00:00:00 2001 From: phofl Date: Mon, 22 Feb 2021 21:06:43 +0100 Subject: [PATCH 3/4] Add comments and refactor test --- pandas/tests/indexing/test_floats.py | 78 ++++++++++------------------ pandas/tests/indexing/test_iloc.py | 3 +- pandas/tests/indexing/test_loc.py | 16 +++--- 3 files changed, 36 insertions(+), 61 deletions(-) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 72db5fede1dc3..d506a413e0527 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -498,96 +498,72 @@ def test_floating_index_doc_example(self): assert s.loc[3] == 2 assert s.iloc[3] == 3 - def test_floating_misc(self): + @pytest.mark.parametrize("indexer_sl", [tm.getitem, tm.loc]) + def test_floating_misc(self, indexer_sl): # related 236 # scalar/slicing of a float index s = Series(np.arange(5), index=np.arange(5) * 2.5, dtype=np.int64) # label based slicing - result1 = s[1.0:3.0] - result2 = s.loc[1.0:3.0] - tm.assert_series_equal(result1, result2) + result = indexer_sl(s)[1.0:3.0] + expected = Series(1, index=[2.5]) + tm.assert_series_equal(result, expected) # exact indexing when found - result1 = s[5.0] - result2 = s.loc[5.0] - assert result1 == result2 - result1 = s[5] - result2 = s.loc[5] - assert result1 == result2 + result = indexer_sl(s)[5.0] + assert result == 2 - assert s[5.0] == s[5] + result = indexer_sl(s)[5] + assert result == 2 # value not found (and no fallbacking at all) # scalar integers with pytest.raises(KeyError, match=r"^4$"): - s.loc[4] - with pytest.raises(KeyError, match=r"^4$"): - s[4] + indexer_sl(s)[4] # fancy floats/integers create the correct entry (as nan) # fancy tests expected = Series([2, 0], index=Float64Index([5.0, 0.0])) for fancy_idx in [[5.0, 0.0], np.array([5.0, 0.0])]: # float - tm.assert_series_equal(s[fancy_idx], expected) - tm.assert_series_equal(s.loc[fancy_idx], expected) + tm.assert_series_equal(indexer_sl(s)[fancy_idx], expected) expected = Series([2, 0], index=Index([5, 0], dtype="int64")) for fancy_idx in [[5, 0], np.array([5, 0])]: # int - tm.assert_series_equal(s[fancy_idx], expected) - tm.assert_series_equal(s.loc[fancy_idx], expected) + tm.assert_series_equal(indexer_sl(s)[fancy_idx], expected) # all should return the same as we are slicing 'the same' - result1 = s.loc[2:5] - result2 = s.loc[2.0:5.0] - result3 = s.loc[2.0:5] - result4 = s.loc[2.1:5] - tm.assert_series_equal(result1, result2) - tm.assert_series_equal(result1, result3) - tm.assert_series_equal(result1, result4) - - # previously this did fallback indexing - result1 = s[2:5] - result2 = s[2.0:5.0] - result3 = s[2.0:5] - result4 = s[2.1:5] + result1 = indexer_sl(s)[2:5] + result2 = indexer_sl(s)[2.0:5.0] + result3 = indexer_sl(s)[2.0:5] + result4 = indexer_sl(s)[2.1:5] tm.assert_series_equal(result1, result2) tm.assert_series_equal(result1, result3) tm.assert_series_equal(result1, result4) - # combined test - result1 = s.loc[2:5] - result2 = s[2:5] + expected = Series([1, 2], index=[2.5, 5.0]) + result = indexer_sl(s)[2:5] - tm.assert_series_equal(result1, result2) + tm.assert_series_equal(result, expected) # list selection - result1 = s[[0.0, 5, 10]] - result2 = s.loc[[0.0, 5, 10]] - result3 = s.iloc[[0, 2, 4]] + result1 = indexer_sl(s)[[0.0, 5, 10]] + result2 = s.iloc[[0, 2, 4]] tm.assert_series_equal(result1, result2) - tm.assert_series_equal(result1, result3) with pytest.raises(KeyError, match="with any missing labels"): - s[[1.6, 5, 10]] - with pytest.raises(KeyError, match="with any missing labels"): - s.loc[[1.6, 5, 10]] + indexer_sl(s)[[1.6, 5, 10]] with pytest.raises(KeyError, match="with any missing labels"): - s[[0, 1, 2]] - with pytest.raises(KeyError, match="with any missing labels"): - s.loc[[0, 1, 2]] + indexer_sl(s)[[0, 1, 2]] - result1 = s.loc[[2.5, 5]] - tm.assert_series_equal(result1, Series([1, 2], index=[2.5, 5.0])) + result = indexer_sl(s)[[2.5, 5]] + tm.assert_series_equal(result, Series([1, 2], index=[2.5, 5.0])) - result1 = s[[2.5]] - result2 = s.loc[[2.5]] - tm.assert_series_equal(result1, result2) - tm.assert_series_equal(result1, Series([1], index=[2.5])) + result = indexer_sl(s)[[2.5]] + tm.assert_series_equal(result, Series([1], index=[2.5])) def test_floating_tuples(self): # see gh-13509 diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index f7cb9e3bebdec..3b3ea1227ba99 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -36,8 +36,7 @@ class TestiLoc(Base): @pytest.mark.parametrize("key", [2, -1, [0, 1, 2]]) - def test_iloc_getitem_int(self, key): - # integer + def test_iloc_getitem_int_and_list_int(self, key): self.check_result( "iloc", key, diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 282fcee8c3499..c9cdd702e7346 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -756,8 +756,8 @@ def test_loc_coercion(self): result = df.iloc[3:] tm.assert_series_equal(result.dtypes, expected) - @pytest.mark.parametrize("indexer", [tm.setitem, tm.loc]) - def test_setitem_new_key_tz(self, indexer): + @pytest.mark.parametrize("indexer_sl", [tm.setitem, tm.loc]) + def test_setitem_new_key_tz(self, indexer_sl): # GH#12862 should not raise on assigning the second value vals = [ pd.to_datetime(42).tz_localize("UTC"), @@ -766,8 +766,8 @@ def test_setitem_new_key_tz(self, indexer): expected = Series(vals, index=["foo", "bar"]) ser = Series(dtype=object) - indexer(ser)["foo"] = vals[0] - indexer(ser)["bar"] = vals[1] + indexer_sl(ser)["foo"] = vals[0] + indexer_sl(ser)["bar"] = vals[1] tm.assert_series_equal(ser, expected) @@ -1562,15 +1562,15 @@ def test_loc_getitem_label_slice_across_dst(self): assert result == expected @pytest.mark.parametrize( - "ix", + "index", [ pd.period_range(start="2017-01-01", end="2018-01-01", freq="M"), timedelta_range(start="1 day", end="2 days", freq="1H"), ], ) - def test_loc_getitem_label_slice_period(self, ix): - ser = ix.to_series() - result = ser.loc[: ix[-2]] + def test_loc_getitem_label_slice_period_timedelta(self, index): + ser = index.to_series() + result = ser.loc[: index[-2]] expected = ser.iloc[:-1] tm.assert_series_equal(result, expected) From f7c6f2f443fa94492508cd6e468843716a6af1e4 Mon Sep 17 00:00:00 2001 From: phofl Date: Mon, 22 Feb 2021 22:16:24 +0100 Subject: [PATCH 4/4] Use fixture --- pandas/tests/indexing/test_floats.py | 1 - pandas/tests/indexing/test_loc.py | 1 - 2 files changed, 2 deletions(-) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index d506a413e0527..21ea6fbd2e3c6 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -498,7 +498,6 @@ def test_floating_index_doc_example(self): assert s.loc[3] == 2 assert s.iloc[3] == 3 - @pytest.mark.parametrize("indexer_sl", [tm.getitem, tm.loc]) def test_floating_misc(self, indexer_sl): # related 236 diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index c9cdd702e7346..829bba5f2930d 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -756,7 +756,6 @@ def test_loc_coercion(self): result = df.iloc[3:] tm.assert_series_equal(result.dtypes, expected) - @pytest.mark.parametrize("indexer_sl", [tm.setitem, tm.loc]) def test_setitem_new_key_tz(self, indexer_sl): # GH#12862 should not raise on assigning the second value vals = [