示例#1
0
def _mod_time_dim(time_dim: pd.DatetimeIndex, freq: str):
    """
    Modify Time dimension so it fits the requirements of the "resample_for_gsee" function
    Parameters
    ----------
    time_dim: array
        with datetime entries
    freq: string
        representing data frequency of na_time

    Returns
    -------
    array
        modified time dimension
    """
    if freq == 'A':
        # Annual data is set to the beginning of the year
        return time_dim.map(lambda x: pd.Timestamp(
            year=x.year, month=1, day=1, hour=0, minute=0))
    elif freq in ['S', 'M']:
        # Seasonal data is set to middle of month, as it is often represented with the day in the middle of the season.
        # Monthly data is set to middle of month
        return time_dim.map(
            lambda x: pd.Timestamp(year=x.year,
                                   month=x.month,
                                   day=int(monthrange(x.year, x.month)[1] / 2),
                                   hour=0,
                                   minute=0))
    elif freq == 'D':
        # Daily data is set to 00:00 hours of the day
        return time_dim.map(lambda x: pd.Timestamp(
            year=x.year, month=x.month, day=x.day, hour=0, minute=0))
    else:
        return time_dim
示例#2
0
    def test_map_bug_1677(self):
        index = DatetimeIndex(['2012-04-25 09:30:00.393000'])
        f = index.asof

        result = index.map(f)
        expected = Index([f(index[0])])
        tm.assert_index_equal(result, expected)
示例#3
0
    def test_map_bug_1677(self):
        index = DatetimeIndex(['2012-04-25 09:30:00.393000'])
        f = index.asof

        result = index.map(f)
        expected = Index([f(index[0])])
        tm.assert_index_equal(result, expected)
示例#4
0
 def get_index_by_days_dict(timestamps: pd.DatetimeIndex, dates = None):
     """Create dictionary with dates as index an intraday timestamps as values
     """
     if(dates is None):
         dates = timestamps.map(pd.Timestamp.date)
     indexes_by_day_dict = timestamps.groupby(dates)
     return indexes_by_day_dict
示例#5
0
 def get_timestamps_by_trading_session_dict(self, timestamps: pd.DatetimeIndex):
     """Create dictionary with dates as index an intraday timestamps as values
     """
     ## TODO: Take iso into consideration here.
     dates = timestamps.map(pd.Timestamp.date)
     indexes_by_day_dict = timestamps.groupby(dates)
     return indexes_by_day_dict