Skip to content

Commit e29bf61

Browse files
committed
Merge pull request #11609 from jreback/warn
WARN: fix performance warning failure on numpy master
2 parents 82d8812 + 61bdda9 commit e29bf61

File tree

2 files changed

+44
-41
lines changed

2 files changed

+44
-41
lines changed

pandas/tseries/holiday.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
from pandas import DateOffset, DatetimeIndex, Series, Timestamp
24
from pandas.compat import add_metaclass
35
from datetime import datetime, timedelta
@@ -192,10 +194,10 @@ def dates(self, start_date, end_date, return_name=False):
192194
"""
193195
start_date = Timestamp(start_date)
194196
end_date = Timestamp(end_date)
195-
196-
filter_start_date = start_date
197+
198+
filter_start_date = start_date
197199
filter_end_date = end_date
198-
200+
199201
if self.year is not None:
200202
dt = Timestamp(datetime(self.year, self.month, self.day))
201203
if return_name:
@@ -208,22 +210,22 @@ def dates(self, start_date, end_date, return_name=False):
208210
if self.days_of_week is not None:
209211
holiday_dates = holiday_dates[np.in1d(holiday_dates.dayofweek,
210212
self.days_of_week)]
211-
213+
212214
if self.start_date is not None:
213215
filter_start_date = max(self.start_date.tz_localize(filter_start_date.tz), filter_start_date)
214216
if self.end_date is not None:
215217
filter_end_date = min(self.end_date.tz_localize(filter_end_date.tz), filter_end_date)
216-
holiday_dates = holiday_dates[(holiday_dates >= filter_start_date) &
218+
holiday_dates = holiday_dates[(holiday_dates >= filter_start_date) &
217219
(holiday_dates <= filter_end_date)]
218220
if return_name:
219221
return Series(self.name, index=holiday_dates)
220222
return holiday_dates
221-
222-
223+
224+
223225
def _reference_dates(self, start_date, end_date):
224226
"""
225227
Get reference dates for the holiday.
226-
228+
227229
Return reference dates for the holiday also returning the year
228230
prior to the start_date and year following the end_date. This ensures
229231
that any offsets to be applied will yield the holidays within
@@ -238,13 +240,13 @@ def _reference_dates(self, start_date, end_date):
238240
year_offset = DateOffset(years=1)
239241
reference_start_date = Timestamp(
240242
datetime(start_date.year-1, self.month, self.day))
241-
243+
242244
reference_end_date = Timestamp(
243245
datetime(end_date.year+1, self.month, self.day))
244246
# Don't process unnecessary holidays
245-
dates = DatetimeIndex(start=reference_start_date, end=reference_end_date,
247+
dates = DatetimeIndex(start=reference_start_date, end=reference_end_date,
246248
freq=year_offset, tz=start_date.tz)
247-
249+
248250
return dates
249251

250252
def _apply_rule(self, dates):
@@ -269,7 +271,11 @@ def _apply_rule(self, dates):
269271
else:
270272
offsets = self.offset
271273
for offset in offsets:
272-
dates += offset
274+
275+
# if we are adding a non-vectorized value
276+
# ignore the PerformanceWarnings:
277+
with warnings.catch_warnings(record=True):
278+
dates += offset
273279
return dates
274280

275281
holiday_calendars = {}
@@ -327,12 +333,12 @@ def __init__(self, name=None, rules=None):
327333

328334
if rules is not None:
329335
self.rules = rules
330-
336+
331337
def rule_from_name(self, name):
332338
for rule in self.rules:
333339
if rule.name == name:
334340
return rule
335-
341+
336342
return None
337343

338344
def holidays(self, start=None, end=None, return_name=False):

pandas/tseries/tests/test_timeseries.py

+24-27
Original file line numberDiff line numberDiff line change
@@ -2637,35 +2637,32 @@ def test_datetime64_with_DateOffset(self):
26372637
assert_func(klass([x - op for x in s]), s - op)
26382638

26392639

2640-
# split by fast/slow path to test perf warning
2641-
off = {False:
2642-
['YearBegin', ('YearBegin', {'month': 5}),
2643-
'YearEnd', ('YearEnd', {'month': 5}),
2644-
'MonthBegin', 'MonthEnd', 'Week', ('Week', {'weekday': 3}),
2645-
'BusinessDay', 'BDay', 'QuarterEnd', 'QuarterBegin'],
2646-
PerformanceWarning:
2647-
['CustomBusinessDay', 'CDay', 'CBMonthEnd','CBMonthBegin',
2648-
'BMonthBegin', 'BMonthEnd', 'BusinessHour', 'BYearBegin',
2649-
'BYearEnd','BQuarterBegin', ('LastWeekOfMonth', {'weekday':2}),
2650-
('FY5253Quarter', {'qtr_with_extra_week': 1, 'startingMonth': 1,
2651-
'weekday': 2, 'variation': 'nearest'}),
2652-
('FY5253',{'weekday': 0, 'startingMonth': 2, 'variation': 'nearest'}),
2653-
('WeekOfMonth', {'weekday': 2, 'week': 2}), 'Easter',
2654-
('DateOffset', {'day': 4}), ('DateOffset', {'month': 5})]}
2640+
# assert these are equal on a piecewise basis
2641+
offsets = ['YearBegin', ('YearBegin', {'month': 5}),
2642+
'YearEnd', ('YearEnd', {'month': 5}),
2643+
'MonthBegin', 'MonthEnd', 'Week', ('Week', {'weekday': 3}),
2644+
'BusinessDay', 'BDay', 'QuarterEnd', 'QuarterBegin',
2645+
'CustomBusinessDay', 'CDay', 'CBMonthEnd','CBMonthBegin',
2646+
'BMonthBegin', 'BMonthEnd', 'BusinessHour', 'BYearBegin',
2647+
'BYearEnd','BQuarterBegin', ('LastWeekOfMonth', {'weekday':2}),
2648+
('FY5253Quarter', {'qtr_with_extra_week': 1, 'startingMonth': 1,
2649+
'weekday': 2, 'variation': 'nearest'}),
2650+
('FY5253',{'weekday': 0, 'startingMonth': 2, 'variation': 'nearest'}),
2651+
('WeekOfMonth', {'weekday': 2, 'week': 2}), 'Easter',
2652+
('DateOffset', {'day': 4}), ('DateOffset', {'month': 5})]
26552653

26562654
for normalize in (True, False):
2657-
for warning, offsets in off.items():
2658-
for do in offsets:
2659-
if isinstance(do, tuple):
2660-
do, kwargs = do
2661-
else:
2662-
do = do
2663-
kwargs = {}
2664-
op = getattr(pd.offsets,do)(5, normalize=normalize, **kwargs)
2665-
with tm.assert_produces_warning(warning):
2666-
assert_func(klass([x + op for x in s]), s + op)
2667-
assert_func(klass([x - op for x in s]), s - op)
2668-
assert_func(klass([op + x for x in s]), op + s)
2655+
for do in offsets:
2656+
if isinstance(do, tuple):
2657+
do, kwargs = do
2658+
else:
2659+
do = do
2660+
kwargs = {}
2661+
op = getattr(pd.offsets,do)(5, normalize=normalize, **kwargs)
2662+
assert_func(klass([x + op for x in s]), s + op)
2663+
assert_func(klass([x - op for x in s]), s - op)
2664+
assert_func(klass([op + x for x in s]), op + s)
2665+
26692666
# def test_add_timedelta64(self):
26702667
# rng = date_range('1/1/2000', periods=5)
26712668
# delta = rng.values[3] - rng.values[1]

0 commit comments

Comments
 (0)