(
self, offset_name, offset_n, tstart, expected_utc_offset, performance_warning
)
| 89 | ) |
| 90 | |
| 91 | def _test_offset( |
| 92 | self, offset_name, offset_n, tstart, expected_utc_offset, performance_warning |
| 93 | ): |
| 94 | offset = DateOffset(**{offset_name: offset_n}) |
| 95 | |
| 96 | if ( |
| 97 | offset_name in ["hour", "minute", "second", "microsecond"] |
| 98 | and offset_n == 1 |
| 99 | and tstart |
| 100 | == Timestamp( |
| 101 | "2013-11-03 01:59:59.999999-0500", tz=pytz.timezone("US/Eastern") |
| 102 | ) |
| 103 | ): |
| 104 | # This addition results in an ambiguous wall time |
| 105 | err_msg = { |
| 106 | "hour": "2013-11-03 01:59:59.999999", |
| 107 | "minute": "2013-11-03 01:01:59.999999", |
| 108 | "second": "2013-11-03 01:59:01.999999", |
| 109 | "microsecond": "2013-11-03 01:59:59.000001", |
| 110 | }[offset_name] |
| 111 | with pytest.raises(ValueError, match=err_msg): |
| 112 | tstart + offset |
| 113 | # While we're here, let's check that we get the same behavior in a |
| 114 | # vectorized path |
| 115 | dti = DatetimeIndex([tstart]) |
| 116 | warn_msg = "Non-vectorized DateOffset" |
| 117 | with pytest.raises(ValueError, match=err_msg): |
| 118 | with tm.assert_produces_warning(performance_warning, match=warn_msg): |
| 119 | dti + offset |
| 120 | return |
| 121 | |
| 122 | t = tstart + offset |
| 123 | if expected_utc_offset is not None: |
| 124 | assert get_utc_offset_hours(t) == expected_utc_offset |
| 125 | |
| 126 | if offset_name == "weeks": |
| 127 | # dates should match |
| 128 | assert t.date() == timedelta(days=7 * offset.kwds["weeks"]) + tstart.date() |
| 129 | # expect the same day of week, hour of day, minute, second, ... |
| 130 | assert ( |
| 131 | t.dayofweek == tstart.dayofweek |
| 132 | and t.hour == tstart.hour |
| 133 | and t.minute == tstart.minute |
| 134 | and t.second == tstart.second |
| 135 | ) |
| 136 | elif offset_name == "days": |
| 137 | # dates should match |
| 138 | assert timedelta(offset.kwds["days"]) + tstart.date() == t.date() |
| 139 | # expect the same hour of day, minute, second, ... |
| 140 | assert ( |
| 141 | t.hour == tstart.hour |
| 142 | and t.minute == tstart.minute |
| 143 | and t.second == tstart.second |
| 144 | ) |
| 145 | elif offset_name in self.valid_date_offsets_singular: |
| 146 | # expect the singular offset value to match between tstart and t |
| 147 | datepart_offset = getattr( |
| 148 | t, offset_name if offset_name != "weekday" else "dayofweek" |
no test coverage detected