forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffset.py
118 lines (86 loc) · 3.22 KB
/
offset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
import warnings
from datetime import datetime
import numpy as np
import pandas as pd
try:
import pandas.tseries.holiday # noqa
except ImportError:
pass
hcal = pd.tseries.holiday.USFederalHolidayCalendar()
# These offests currently raise a NotImplimentedError with .apply_index()
non_apply = [pd.offsets.Day(),
pd.offsets.BYearEnd(),
pd.offsets.BYearBegin(),
pd.offsets.BQuarterEnd(),
pd.offsets.BQuarterBegin(),
pd.offsets.BMonthEnd(),
pd.offsets.BMonthBegin(),
pd.offsets.CustomBusinessDay(),
pd.offsets.CustomBusinessDay(calendar=hcal),
pd.offsets.CustomBusinessMonthBegin(calendar=hcal),
pd.offsets.CustomBusinessMonthEnd(calendar=hcal),
pd.offsets.CustomBusinessMonthEnd(calendar=hcal)]
other_offsets = [pd.offsets.YearEnd(), pd.offsets.YearBegin(),
pd.offsets.QuarterEnd(), pd.offsets.QuarterBegin(),
pd.offsets.MonthEnd(), pd.offsets.MonthBegin(),
pd.offsets.DateOffset(months=2, days=2),
pd.offsets.BusinessDay(), pd.offsets.SemiMonthEnd(),
pd.offsets.SemiMonthBegin()]
offsets = non_apply + other_offsets
class ApplyIndex(object):
params = other_offsets
param_names = ['offset']
def setup(self, offset):
N = 10000
self.rng = pd.date_range(start='1/1/2000', periods=N, freq='T')
def time_apply_index(self, offset):
offset.apply_index(self.rng)
class OnOffset(object):
params = offsets
param_names = ['offset']
def setup(self, offset):
self.dates = [datetime(2016, m, d)
for m in [10, 11, 12]
for d in [1, 2, 3, 28, 29, 30, 31]
if not (m == 11 and d == 31)]
def time_on_offset(self, offset):
for date in self.dates:
offset.onOffset(date)
class OffsetSeriesArithmetic(object):
params = offsets
param_names = ['offset']
def setup(self, offset):
N = 1000
rng = pd.date_range(start='1/1/2000', periods=N, freq='T')
self.data = pd.Series(rng)
def time_add_offset(self, offset):
with warnings.catch_warnings(record=True):
self.data + offset
class OffsetDatetimeIndexArithmetic(object):
params = offsets
param_names = ['offset']
def setup(self, offset):
N = 1000
self.data = pd.date_range(start='1/1/2000', periods=N, freq='T')
def time_add_offset(self, offset):
with warnings.catch_warnings(record=True):
self.data + offset
class OffestDatetimeArithmetic(object):
params = offsets
param_names = ['offset']
def setup(self, offset):
self.date = datetime(2011, 1, 1)
self.dt64 = np.datetime64('2011-01-01 09:00Z')
def time_apply(self, offset):
offset.apply(self.date)
def time_apply_np_dt64(self, offset):
offset.apply(self.dt64)
def time_add(self, offset):
self.date + offset
def time_add_10(self, offset):
self.date + (10 * offset)
def time_subtract(self, offset):
self.date - offset
def time_subtract_10(self, offset):
self.date - (10 * offset)