예제 #1
0
    def test_dataframe(self):
        ind = pd.date_range(start='1/1/2002', end='12/30/2008', freq="30min")

        # test converting a dataframe with 1 col. This errored while
        # multiple columns worked fine
        df = pd.DataFrame({'returns': np.random.randn(len(ind))}, index=ind)
        conv.convert_df_to_xts(df)

        # test with two columns
        df['bob'] = 3
        conv.convert_df_to_xts(df)
예제 #2
0
    def test_dataframe(self):
        ind = pd.date_range(start='1/1/2002', end='12/30/2008', freq="30min")

        # test converting a dataframe with 1 col. This errored while
        # multiple columns worked fine
        df = pd.DataFrame({'returns': np.random.randn(len(ind))}, index=ind)
        conv.convert_df_to_xts(df)


        # test with two columns
        df['bob'] = 3
        conv.convert_df_to_xts(df)
예제 #3
0
파일: api.py 프로젝트: dalejung/trtools
def pd_py2ri(o):
    """ 
    """
    res = None
    if isinstance(o, pd.Series): 
        o = pd.DataFrame(o, index=o.index)

    if isinstance(o, pd.DataFrame): 
        if isinstance(o.index, pd.DatetimeIndex):
            res = rconv.convert_df_to_xts(o)
        else:
            res = rcom.convert_to_r_dataframe(o)

    if isinstance(o, pd.DatetimeIndex): 
        res = rconv.convert_datetime_index(o)

    if isinstance(o, pd.Timestamp): 
        res = rconv.convert_timestamp(o)
        
    if res is None:
        try:
            res = numpy2ri.py2ri(o)
        except:
            res = robjects.default_converter.py2ri(o)

    return res
예제 #4
0
파일: api.py 프로젝트: femtotrader/trtools
def pd_py2ri(o):
    """ 
    """
    res = None
    if isinstance(o, pd.Series):
        o = pd.DataFrame(o, index=o.index)

    if isinstance(o, pd.DataFrame):
        if isinstance(o.index, pd.DatetimeIndex):
            res = rconv.convert_df_to_xts(o)
        else:
            res = rcom.convert_to_r_dataframe(o)

    if isinstance(o, pd.DatetimeIndex):
        res = rconv.convert_datetime_index(o)

    if isinstance(o, pd.Timestamp):
        res = rconv.convert_timestamp(o)

    if res is None:
        try:
            res = numpy2ri.py2ri(o)
        except:
            res = robjects.default_converter.py2ri(o)

    return res