Skip to content

Commit 2c1b5c7

Browse files
committed
TST: add tests for indexing Series with duplicate periods, close #1154
1 parent 6f65882 commit 2c1b5c7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tseries/tests/test_period.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,25 @@ def _get_with_delta(delta, freq='A-DEC'):
945945
exp_index = _get_with_delta(delta)
946946
self.assert_(result.index.equals(exp_index))
947947

948+
def test_index_duplicate_periods(self):
949+
# monotonic
950+
idx = PeriodIndex([2000, 2007, 2007, 2009, 2009], freq='A-JUN')
951+
ts = Series(np.random.randn(len(idx)), index=idx)
952+
953+
result = ts[2007]
954+
expected = ts[1:3]
955+
assert_series_equal(result, expected)
956+
result[:] = 1
957+
self.assert_((ts[1:3] == 1).all())
958+
959+
# not monotonic
960+
idx = PeriodIndex([2000, 2007, 2007, 2009, 2007], freq='A-JUN')
961+
ts = Series(np.random.randn(len(idx)), index=idx)
962+
963+
result = ts[2007]
964+
expected = ts[idx == 2007]
965+
assert_series_equal(result, expected)
966+
948967
def test_constructor(self):
949968
ii = PeriodIndex(freq='A', start='1/1/2001', end='12/1/2009')
950969
assert_equal(len(ii), 9)

0 commit comments

Comments
 (0)