|
| 1 | +Author: Rebecca N. Palmer < [email protected]> |
| 2 | +Bug-Debian: https://bugs.debian.org/858260 |
| 3 | +Last-Update: Sat, 1 Apr 2017 23:21:31 +0100 |
| 4 | +Description: Use tiinfo correctly |
| 5 | + The underlying issue (but not strictly a bug as the documentation |
| 6 | + specifically says not to do that - |
| 7 | + http://sources.debian.net/src/python-tz/2016.7-0.2/pytz/tzinfo.py/#L247 |
| 8 | + ) is that passing a pytz tzinfo to the datetime constructor uses its |
| 9 | + first listed offset, not its correct offset for that date: |
| 10 | + . |
| 11 | + >>> datetime.datetime(2017,4,1,tzinfo=pytz.timezone('Europe/London')) |
| 12 | + datetime.datetime(2017, 4, 1, 0, 0, tzinfo=<DstTzInfo 'Europe/London' |
| 13 | + GMT0:00:00 STD>) |
| 14 | + >>> pytz.timezone('Europe/London').localize(datetime.datetime(2017,4,1)) |
| 15 | + datetime.datetime(2017, 4, 1, 0, 0, tzinfo=<DstTzInfo 'Europe/London' |
| 16 | + BST+1:00:00 DST>) |
| 17 | + |
| 18 | +--- a/pandas/tests/test_multilevel.py |
| 19 | ++++ b/pandas/tests/test_multilevel.py |
| 20 | +@@ -84,9 +84,9 @@ class TestMultiLevel(tm.TestCase): |
| 21 | + # GH 7112 |
| 22 | + import pytz |
| 23 | + tz = pytz.timezone('Asia/Tokyo') |
| 24 | +- expected_tuples = [(1.1, datetime.datetime(2011, 1, 1, tzinfo=tz)), |
| 25 | +- (1.2, datetime.datetime(2011, 1, 2, tzinfo=tz)), |
| 26 | +- (1.3, datetime.datetime(2011, 1, 3, tzinfo=tz))] |
| 27 | ++ expected_tuples = [(1.1, tz.localize(datetime.datetime(2011, 1, 1))), |
| 28 | ++ (1.2, tz.localize(datetime.datetime(2011, 1, 2))), |
| 29 | ++ (1.3, tz.localize(datetime.datetime(2011, 1, 3)))] |
| 30 | + expected = Index([1.1, 1.2, 1.3] + expected_tuples) |
| 31 | + self.assert_index_equal(result, expected) |
| 32 | + |
| 33 | +@@ -104,9 +104,9 @@ class TestMultiLevel(tm.TestCase): |
| 34 | + |
| 35 | + result = midx_lv3.append(midx_lv2) |
| 36 | + expected = Index._simple_new( |
| 37 | +- np.array([(1.1, datetime.datetime(2011, 1, 1, tzinfo=tz), 'A'), |
| 38 | +- (1.2, datetime.datetime(2011, 1, 2, tzinfo=tz), 'B'), |
| 39 | +- (1.3, datetime.datetime(2011, 1, 3, tzinfo=tz), 'C')] + |
| 40 | ++ np.array([(1.1, tz.localize(datetime.datetime(2011, 1, 1)), 'A'), |
| 41 | ++ (1.2, tz.localize(datetime.datetime(2011, 1, 2)), 'B'), |
| 42 | ++ (1.3, tz.localize(datetime.datetime(2011, 1, 3)), 'C')] + |
| 43 | + expected_tuples), None) |
| 44 | + self.assert_index_equal(result, expected) |
| 45 | + |
0 commit comments