def test_convert_posixct_to_index(self):
        ind = pd.date_range(start='1/1/2002', end='12/30/2008', freq="30min")
        ri = conv.convert_datetime_index_num(ind)

        # test converting back 'UTC'
        dt = conv.convert_posixct_to_index(ri)
        tm.assert_almost_equal(dt, ind,)

        # test 'US/Eastern'
        # At one point this failed due to DatetimeIndex being 
        # given a tz. DatetimeIndex needs to be initialied to UTC
        # and then converted
        ri.do_slot_assign('tzone', StrSexpVector(['US/Eastern']))
        dt = conv.convert_posixct_to_index(ri)
        assert dt.tz.zone == 'US/Eastern'
        assert ind.tz is None
        tm.assert_almost_equal(dt, ind)

        ind = ind.tz_localize('UTC')
        est_ind = ind.tz_convert('US/Eastern')
        est_ri = conv.convert_datetime_index_num(est_ind)
        assert est_ri.do_slot('tzone')[0] == 'US/Eastern'
        est_dt = conv.convert_posixct_to_index(est_ri)
        tm.assert_almost_equal(est_dt, est_ind)
        assert est_dt.tz.zone == 'US/Eastern'
Beispiel #2
0
    def test_convert_posixct_to_index(self):
        ind = pd.date_range(start='1/1/2002', end='12/30/2008', freq="30min")
        ri = conv.convert_datetime_index_num(ind)

        # test converting back 'UTC'
        dt = conv.convert_posixct_to_index(ri)
        tm.assert_almost_equal(
            dt,
            ind,
        )

        # test 'US/Eastern'
        # At one point this failed due to DatetimeIndex being
        # given a tz. DatetimeIndex needs to be initialied to UTC
        # and then converted
        ri.do_slot_assign('tzone', StrSexpVector(['US/Eastern']))
        dt = conv.convert_posixct_to_index(ri)
        assert dt.tz.zone == 'US/Eastern'
        assert ind.tz is None
        tm.assert_almost_equal(dt, ind)

        ind = ind.tz_localize('UTC')
        est_ind = ind.tz_convert('US/Eastern')
        est_ri = conv.convert_datetime_index_num(est_ind)
        assert est_ri.do_slot('tzone')[0] == 'US/Eastern'
        est_dt = conv.convert_posixct_to_index(est_ri)
        tm.assert_almost_equal(est_dt, est_ind)
        assert est_dt.tz.zone == 'US/Eastern'
    def test_convert_datetime(self):
        ind = pd.date_range(start='1/1/2002', end='12/30/2008', freq="30min")
        ri = conv.convert_datetime_index_num(ind)
        tm.assert_almost_equal(ri[0], ind.asi8[0] / 1E9)

        assert ri.do_slot('tzone')[0] == 'UTC'

        # convert back to datetime
        conv_dates = pd.Series(ri).astype(np.dtype('M8[s]'))
        tm.assert_almost_equal(conv_dates, ind)
Beispiel #4
0
    def test_convert_datetime(self):
        ind = pd.date_range(start='1/1/2002', end='12/30/2008', freq="30min")
        ri = conv.convert_datetime_index_num(ind)
        tm.assert_almost_equal(ri[0], ind.asi8[0] / 1E9)

        assert ri.do_slot('tzone')[0] == 'UTC'

        # convert back to datetime
        conv_dates = pd.Series(ri).astype(np.dtype('M8[s]'))
        tm.assert_almost_equal(conv_dates, ind)