|
6 | 6 | from distutils.version import LooseVersion
|
7 | 7 |
|
8 | 8 | import dateutil
|
9 |
| -from dateutil.tz import gettz, tzlocal |
| 9 | +from dateutil.tz import gettz, tzlocal, tzutc |
10 | 10 | import numpy as np
|
11 | 11 | import pytest
|
12 | 12 | import pytz
|
@@ -434,24 +434,30 @@ def test_dti_tz_localize_utc_conversion(self, tz):
|
434 | 434 | with pytest.raises(pytz.NonExistentTimeError):
|
435 | 435 | rng.tz_localize(tz)
|
436 | 436 |
|
| 437 | + @pytest.mark.parametrize('tz', [ |
| 438 | + 'UTC', 'US/Eastern', 'Europe/London', 'Asia/Tokyo', 'Australia/NSW', |
| 439 | + 'dateutil/US/Pacific', 'dateutil/Asia/Singapore', tzutc(), |
| 440 | + pytz.FixedOffset(300), pytz.FixedOffset(0), pytz.FixedOffset(-300) |
| 441 | + ]) |
437 | 442 | @pytest.mark.parametrize('idx', [
|
438 |
| - date_range(start='2014-01-01', end='2014-12-31', freq='M'), |
439 |
| - date_range(start='2014-01-01', end='2014-12-31', freq='D'), |
440 |
| - date_range(start='2014-01-01', end='2014-03-01', freq='H'), |
441 |
| - date_range(start='2014-08-01', end='2014-10-31', freq='T') |
| 443 | + date_range(start='2014-12-01', end='2015-02-28', freq='D'), |
| 444 | + date_range(start='2014-05-01', end='2015-07-31', freq='D'), |
| 445 | + date_range(start='2014-01-01', end='2014-02-28', freq='H'), |
| 446 | + date_range(start='2014-08-01', end='2014-09-30', freq='15T') |
442 | 447 | ])
|
443 |
| - def test_dti_tz_localize_roundtrip(self, tz_aware_fixture, idx): |
444 |
| - tz = tz_aware_fixture |
| 448 | + def test_dti_tz_localize_roundtrip(self, tz, idx): |
| 449 | + # note: this tz tests that a tz-naive index can be localized |
| 450 | + # and de-localized successfully, when there are no DST transitions |
| 451 | + # in the range. |
445 | 452 | localized = idx.tz_localize(tz)
|
446 |
| - expected = date_range(start=idx[0], end=idx[-1], freq=idx.freq, |
447 |
| - tz=tz) |
448 |
| - tm.assert_index_equal(localized, expected) |
| 453 | + |
| 454 | + # cant localize a tz-aware object |
449 | 455 | with pytest.raises(TypeError):
|
450 | 456 | localized.tz_localize(tz)
|
451 | 457 |
|
452 | 458 | reset = localized.tz_localize(None)
|
453 |
| - tm.assert_index_equal(reset, idx) |
454 | 459 | assert reset.tzinfo is None
|
| 460 | + tm.assert_index_equal(reset, idx) |
455 | 461 |
|
456 | 462 | def test_dti_tz_localize_naive(self):
|
457 | 463 | rng = date_range('1/1/2011', periods=100, freq='H')
|
|
0 commit comments