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'
Example #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'
Example #3
0
def to_py(o, skip_list=False):
    """
        Converts to python object if possible. 
        Otherwise wraps in ROBjectWrapper
    """
    res = None
    try:
        rcls = o.do_slot("class")
        rcls = list(rcls)
    except LookupError as le:
        rcls = []

    try:
        rclass = list(o.rclass)
    except:
        rclass = []


    classes = rclass + rcls

    if isinstance(o, SexpVector) and len(classes) > 0:
        if 'xts' in classes:
            res = rconv.convert_xts_to_df(o)
        elif 'POSIXct' in classes:
            res = rconv.convert_posixct_to_index(o)
        elif 'logical' in classes:
            res = rcommon._convert_vector(o)

    if res is None and isinstance(o, DataFrame):
        res = rcommon.convert_robj(o) 

    if res is None and isinstance(o, ListVector) and not skip_list:
        res = convert_ListVector(o)

    if res is None:
        try:
            res = rcommon.convert_robj(o) # fallback to pandas
        except:
            pass

    try: 
        if len(res) == 1:
            return res[0]
    except:
        pass
        
    if res is None and isinstance(o, SexpVector):
        res = RObjectWrapper(o)

    if res is None:
        res = o

    return res
Example #4
0
    except LookupError, le:
        rcls = []

    try:
        rclass = list(o.rclass)
    except:
        rclass = []


    classes = rclass + rcls

    if isinstance(o, SexpVector) and len(classes) > 0:
        if 'xts' in classes:
            res = rconv.convert_xts_to_df(o)
        elif 'POSIXct' in classes:
            res = rconv.convert_posixct_to_index(o)
        elif 'logical' in classes:
            res = rcommon._convert_vector(o)

    if res is None and isinstance(o, DataFrame):
        res = rcommon.convert_robj(o) 

    if res is None and isinstance(o, ListVector) and not skip_list:
        res = convert_ListVector(o)

    if res is None:
        try:
            res = rcommon.convert_robj(o) # fallback to pandas
        except:
            pass