Ejemplo n.º 1
0
def test_year_quarter_to_datetime():
    """ Test year and quarter to datetime: """
    #             Date       Year   Q
    test_data = [['2005-03-31', '05', '1'], ['2011-12-31', '11', '4'],
                 ['2015-09-30', '15', '3']]
    for [date_str, year, quarter] in test_data:
        from_time_tools = time_tools.year_quarter_to_datetime(year, quarter)
        expected = np.datetime64(date_str)
        nose.tools.eq_(
            from_time_tools, expected, 'Wrong datetime detected: %s -> %s' %
            (str(from_time_tools), str(expected)))
Ejemplo n.º 2
0
def test_year_quarter_to_datetime():
    """ Test year and quarter to datetime: """
    #             Date       Year   Q 
    test_data = [['2005-03-31', '05', '1'],
                 ['2011-12-31', '11', '4'],
                 ['2015-09-30', '15', '3']]
    for [date_str, year, quarter] in test_data:
        from_time_tools = time_tools.year_quarter_to_datetime(year, quarter)
        expected = np.datetime64(date_str)
        nose.tools.eq_(from_time_tools, expected,
                       'Wrong datetime detected: %s -> %s'%(
                           str(from_time_tools), str(expected)))
Ejemplo 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
Ejemplo 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