diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index 61a9909926efe..e2f40c6267493 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -604,28 +604,24 @@ def test_indexing_over_size_cutoff(): _index._SIZE_CUTOFF = old_cutoff -def test_indexing_over_size_cutoff_period_index(): +def test_indexing_over_size_cutoff_period_index(monkeypatch): # GH 27136 - old_cutoff = _index._SIZE_CUTOFF - try: - _index._SIZE_CUTOFF = 1000 + monkeypatch.setattr(_index, "_SIZE_CUTOFF", 1000) - n = 1100 - idx = pd.period_range("1/1/2000", freq="T", periods=n) - assert idx._engine.over_size_threshold + n = 1100 + idx = pd.period_range("1/1/2000", freq="T", periods=n) + assert idx._engine.over_size_threshold - s = pd.Series(np.random.randn(len(idx)), index=idx) + s = pd.Series(np.random.randn(len(idx)), index=idx) - pos = n - 1 - timestamp = idx[pos] - assert timestamp in s.index + pos = n - 1 + timestamp = idx[pos] + assert timestamp in s.index - # it works! - s[timestamp] - assert len(s.loc[[timestamp]]) > 0 - finally: - _index._SIZE_CUTOFF = old_cutoff + # it works! + s[timestamp] + assert len(s.loc[[timestamp]]) > 0 def test_indexing_unordered():