Esempio n. 1
0
def test_time_diff_in_quarters():
    """ Test convert time difference to nearest quarters: """
    test_data = [['2005-01', '2005-04', 1],
                 ['2015-01-01', '2015-08-07', 2],
                 ['2015-01-01', '2015-07-07', 2],   # Check that it rounds up.
                 ['2015-12-31', '2015-01-01', -4],  # Check negative.
                 ]
    for [from_time_str, to_time_str, d_quarter] in test_data:
        t1 = np.datetime64(from_time_str)
        t2 = np.datetime64(to_time_str)
        dt = time_tools.time_diff_in_quarters(t1, t2)
        nose.tools.eq_(dt, d_quarter, ''.join((
                       'Error in delta quarter result, expected:',
                       str(d_quarter), 'return was:', str(dt))))
Esempio n. 2
0
def test_time_diff_in_quarters():
    """ Test convert time difference to nearest quarters: """
    test_data = [
        ['2005-01', '2005-04', 1],
        ['2015-01-01', '2015-08-07', 2],
        ['2015-01-01', '2015-07-07', 2],  # Check that it rounds up.
        ['2015-12-31', '2015-01-01', -4],  # Check negative.
    ]
    for [from_time_str, to_time_str, d_quarter] in test_data:
        t1 = np.datetime64(from_time_str)
        t2 = np.datetime64(to_time_str)
        dt = time_tools.time_diff_in_quarters(t1, t2)
        nose.tools.eq_(
            dt, d_quarter, ''.join(('Error in delta quarter result, expected:',
                                    str(d_quarter), 'return was:', str(dt))))
Esempio n. 3
0
    def remap_to_relative_time(self,
                               prediction_data,
                               actual_data,
                               prediction_horizon=16):
        """ Convert the data to columns of how old the prediction is.
        """
        # Create a new empty DataFrame, and add the CPI column.
        index = self.raw_data.index
        slength = len(index)
        pred_relative = pd.DataFrame(index=index, data=None)
        colname_prefix = actual_data.name

        # Create the column for relative predictions, and fill with NaN.
        pred_relative_col_names = []
        # TODO(Camilla): Hvis språkbruken er "ett kvartal frem" for første
        # prediksjon i banen, bytt om til range(1, prediction_horizon+1).
        for dq in range(0, prediction_horizon):
            col_name = colname_prefix + '_dQ' + str(dq)
            pred_relative_col_names.append(col_name)
            ser = pd.Series(np.empty(slength), index=index)
            pred_relative[col_name] = ser
            pred_relative[col_name] = np.NaN

        # Okay now we have an empty frame. Let's fill it up...

        # Loop through all the PPR columns in CPI predictions.
        for col_name in prediction_data:
            col_info = decode_column_name.decode(col_name)
            ppr_date = time_tools.year_quarter_to_datetime(
                col_info['year'], col_info['quarter'])
            # Loop through each prediction in this PPR.
            for date in prediction_data.index:
                if date is pd.NaT:
                    continue
                prediction = prediction_data.loc[date, col_name]
                if not math.isnan(prediction):
                    # How old is the prediction, in quarters?
                    dq = time_tools.time_diff_in_quarters(ppr_date, date)
                    n_col_name = pred_relative_col_names[dq]
                    # Insert prediction, in the new dataframe.
                    pred_relative.loc[date, n_col_name] = (
                        prediction_data.loc[date, col_name])
                    #print 'Put prediction from ', col_name,
                    #      ' for ', date.strftime('%Y-%m-%d'),
                    #      ' in ', n_col_name
        return pred_relative
Esempio n. 4
0
    def remap_to_relative_time(self, prediction_data, actual_data,
                               prediction_horizon=16):
        """ Convert the data to columns of how old the prediction is.
        """
        # Create a new empty DataFrame, and add the CPI column.
        index = self.raw_data.index
        slength = len(index)
        pred_relative = pd.DataFrame(index=index, data=None)
        colname_prefix = actual_data.name

        # Create the column for relative predictions, and fill with NaN.
        pred_relative_col_names = []
        # TODO(Camilla): Hvis språkbruken er "ett kvartal frem" for første
        # prediksjon i banen, bytt om til range(1, prediction_horizon+1).
        for dq in range(0, prediction_horizon):
            col_name = colname_prefix + '_dQ' + str(dq)
            pred_relative_col_names.append(col_name)
            ser = pd.Series(np.empty(slength), index=index)
            pred_relative[col_name] = ser
            pred_relative[col_name] = np.NaN
        
        # Okay now we have an empty frame. Let's fill it up...

        # Loop through all the PPR columns in CPI predictions.
        for col_name in prediction_data:
            col_info = decode_column_name.decode(col_name)
            ppr_date = time_tools.year_quarter_to_datetime(
                col_info['year'], col_info['quarter'])
            # Loop through each prediction in this PPR.
            for date in prediction_data.index:
                if date is pd.NaT:
                    continue
                prediction = prediction_data.loc[date, col_name]
                if not math.isnan(prediction):
                    # How old is the prediction, in quarters?
                    dq = time_tools.time_diff_in_quarters(ppr_date, date)
                    n_col_name = pred_relative_col_names[dq]
                    # Insert prediction, in the new dataframe.
                    pred_relative.loc[date, n_col_name] = (
                        prediction_data.loc[date, col_name])
                    #print 'Put prediction from ', col_name,
                    #      ' for ', date.strftime('%Y-%m-%d'),
                    #      ' in ', n_col_name
        return pred_relative