|
21 | 21 | from pandas.compat.numpy import np_array_datetime64_compat
|
22 | 22 | from pandas.core.dtypes.common import is_datetime64_ns_dtype
|
23 | 23 | from pandas.util import testing as tm
|
| 24 | +import pandas.util._test_decorators as td |
24 | 25 | from pandas.util.testing import assert_series_equal, _skip_if_has_locale
|
25 | 26 | from pandas import (isna, to_datetime, Timestamp, Series, DataFrame,
|
26 | 27 | Index, DatetimeIndex, NaT, date_range, compat)
|
@@ -187,6 +188,56 @@ def test_to_datetime_format_weeks(self, cache):
|
187 | 188 |
|
188 | 189 | class TestToDatetime(object):
|
189 | 190 |
|
| 191 | + @td.skip_if_windows # `tm.set_timezone` does not work in windows |
| 192 | + def test_to_datetime_now(self): |
| 193 | + # See GH#18666 |
| 194 | + with tm.set_timezone('US/Eastern'): |
| 195 | + npnow = np.datetime64('now').astype('datetime64[ns]') |
| 196 | + pdnow = pd.to_datetime('now') |
| 197 | + pdnow2 = pd.to_datetime(['now'])[0] |
| 198 | + |
| 199 | + # These should all be equal with infinite perf; this gives |
| 200 | + # a generous margin of 10 seconds |
| 201 | + assert abs(pdnow.value - npnow.astype(np.int64)) < 1e10 |
| 202 | + assert abs(pdnow2.value - npnow.astype(np.int64)) < 1e10 |
| 203 | + |
| 204 | + assert pdnow.tzinfo is None |
| 205 | + assert pdnow2.tzinfo is None |
| 206 | + |
| 207 | + @td.skip_if_windows # `tm.set_timezone` does not work in windows |
| 208 | + def test_to_datetime_today(self): |
| 209 | + # See GH#18666 |
| 210 | + # Test with one timezone far ahead of UTC and another far behind, so |
| 211 | + # one of these will _almost_ alawys be in a different day from UTC. |
| 212 | + # Unfortunately this test between 12 and 1 AM Samoa time |
| 213 | + # this both of these timezones _and_ UTC will all be in the same day, |
| 214 | + # so this test will not detect the regression introduced in #18666. |
| 215 | + with tm.set_timezone('Pacific/Auckland'): # 12-13 hours ahead of UTC |
| 216 | + nptoday = np.datetime64('today').astype('datetime64[ns]') |
| 217 | + pdtoday = pd.to_datetime('today') |
| 218 | + pdtoday2 = pd.to_datetime(['today'])[0] |
| 219 | + |
| 220 | + # These should all be equal with infinite perf; this gives |
| 221 | + # a generous margin of 10 seconds |
| 222 | + assert abs(pdtoday.value - nptoday.astype(np.int64)) < 1e10 |
| 223 | + assert abs(pdtoday2.value - nptoday.astype(np.int64)) < 1e10 |
| 224 | + |
| 225 | + assert pdtoday.tzinfo is None |
| 226 | + assert pdtoday2.tzinfo is None |
| 227 | + |
| 228 | + with tm.set_timezone('US/Samoa'): # 11 hours behind UTC |
| 229 | + nptoday = np.datetime64('today').astype('datetime64[ns]') |
| 230 | + pdtoday = pd.to_datetime('today') |
| 231 | + pdtoday2 = pd.to_datetime(['today'])[0] |
| 232 | + |
| 233 | + # These should all be equal with infinite perf; this gives |
| 234 | + # a generous margin of 10 seconds |
| 235 | + assert abs(pdtoday.value - nptoday.astype(np.int64)) < 1e10 |
| 236 | + assert abs(pdtoday2.value - nptoday.astype(np.int64)) < 1e10 |
| 237 | + |
| 238 | + assert pdtoday.tzinfo is None |
| 239 | + assert pdtoday2.tzinfo is None |
| 240 | + |
190 | 241 | @pytest.mark.parametrize('cache', [True, False])
|
191 | 242 | def test_to_datetime_dt64s(self, cache):
|
192 | 243 | in_bound_dts = [
|
|
0 commit comments