

def test_getitem_setitem_periodindex(self):
    from pandas import period_range
    N = 50
    rng = period_range('1/1/1990', periods=N, freq='H')
    ts = Series(np.random.randn(N), index=rng)
    result = ts['1990-01-01 04']
    expected = ts[4]
    self.assertEqual(result, expected)
    result = ts.copy()
    result['1990-01-01 04'] = 0
    result['1990-01-01 04'] = ts[4]
    assert_series_equal(result, ts)
    result = ts['1990-01-01 04':'1990-01-01 07']
    expected = ts[4:8]
    assert_series_equal(result, expected)
    result = ts.copy()
    result['1990-01-01 04':'1990-01-01 07'] = 0
    result['1990-01-01 04':'1990-01-01 07'] = ts[4:8]
    assert_series_equal(result, ts)
    lb = '1990-01-01 04'
    rb = '1990-01-01 07'
    result = ts[((ts.index >= lb) & (ts.index <= rb))]
    expected = ts[4:8]
    assert_series_equal(result, expected)
    result = ts[ts.index[4]]
    expected = ts[4]
    self.assertEqual(result, expected)
    result = ts[ts.index[4:8]]
    expected = ts[4:8]
    assert_series_equal(result, expected)
    result = ts.copy()
    result[ts.index[4:8]] = 0
    result[4:8] = ts[4:8]
    assert_series_equal(result, ts)

dataset/ETHPy150Open pydata/pandas/pandas/tests/series/test_timeseries.py TestSeriesTimeSeries.test_getitem_setitem_periodindex/original