Ejemplo n.º 1
0
def slice_source_df_by_date_range(freq, start_date, end_date=None):
    """Main function to produce selections of dataframes"""
    
    dfa, dfq, dfm = get_reshaped_dfs()
    start_year, start_period = date_to_tuple(start_date)
    
    # define end date
    if end_date is not None:
        end_year, end_period = date_to_tuple(start_date)
    else:
        end_year = date.today().year + 1
        end_period = 1
        
    # select which dataframe to use and define indexer
    if freq == 'a':
        df = dfa
        indexer = (df.index >= start_year) & (df.index <= end_year)
    elif freq == 'q':
        df = dfq
        d1 = get_end_of_quarterdate(start_year, start_period)
        d2 = get_end_of_quarterdate(end_year, end_period)
        indexer = (df.index >= d1) & (df.index <= d2)
    elif freq == 'm':
        df = dfm
        d1 = get_end_of_monthdate(start_year, start_period)
        d2 = get_end_of_monthdate(end_year, end_period)
        indexer = (df.index >= d1) & (df.index <= d2)
    else:
        raise ValueError("Frequency must be 'a', 'q' or 'm'. Provided: %s" % freq)

    return df[indexer]
Ejemplo n.º 2
0
 def test_database(self):
     gen = list(
         stream_flat_data(
             get_labelled_rows(raw_data_file(), spec_file(), cfg_file())))
     stream_to_database(gen)
     dfa, dfq, dfm = get_reshaped_dfs()
     self.assertEqual(dfa.loc[2014, 'I_yoy'], 97.3)
Ejemplo n.º 3
0
def slice_source_df_by_date_range(freq, start_date, end_date=None):
    """Main function to produce selections of dataframes"""

    dfa, dfq, dfm = get_reshaped_dfs()
    start_year, start_period = date_to_tuple(start_date)

    # define end date
    if end_date is not None:
        end_year, end_period = date_to_tuple(start_date)
    else:
        end_year = date.today().year + 1
        end_period = 1

    # select which dataframe to use and define indexer
    if freq == 'a':
        df = dfa
        indexer = (df.index >= start_year) & (df.index <= end_year)
    elif freq == 'q':
        df = dfq
        d1 = get_end_of_quarterdate(start_year, start_period)
        d2 = get_end_of_quarterdate(end_year, end_period)
        indexer = (df.index >= d1) & (df.index <= d2)
    elif freq == 'm':
        df = dfm
        d1 = get_end_of_monthdate(start_year, start_period)
        d2 = get_end_of_monthdate(end_year, end_period)
        indexer = (df.index >= d1) & (df.index <= d2)
    else:
        raise ValueError("Frequency must be 'a', 'q' or 'm'. Provided: %s" %
                         freq)

    return df[indexer]
Ejemplo n.º 4
0
def test_database(labelled_rows):
    wipe_db_tables()
    gen = list(stream_flat_data(labelled_rows))
    stream_to_database(gen)
    dfa, dfq, dfm = get_reshaped_dfs()
    assert dfa.loc[2014, 'I_yoy'] == 97.3
Ejemplo n.º 5
0
def get_all_dfs():
    return get_reshaped_dfs()
Ejemplo n.º 6
0
def get_all_dfs():
    return get_reshaped_dfs()
Ejemplo n.º 7
0
def test_database(labelled_rows):
    wipe_db_tables()
    gen = list(stream_flat_data(labelled_rows))
    stream_to_database(gen)
    dfa, dfq, dfm = get_reshaped_dfs()
    assert dfa.loc[2014, 'I_yoy'] == 97.3
Ejemplo n.º 8
0
 def test_database(self):
     gen = list(stream_flat_data(get_labelled_rows(raw_data_file(), spec_file(), cfg_file())))
     stream_to_database(gen)
     dfa, dfq, dfm = get_reshaped_dfs()
     self.assertEqual(dfa.loc[2014, 'I_yoy'], 97.3)