|
1 |
| -from datetime import date |
| 1 | +from datetime import date, timedelta |
2 | 2 |
|
3 | 3 | import dateutil
|
4 | 4 | import numpy as np
|
@@ -44,6 +44,45 @@ def test_reindex_preserves_tz_if_target_is_empty_list_or_array(self):
|
44 | 44 | assert str(index.reindex([])[0].tz) == "US/Eastern"
|
45 | 45 | assert str(index.reindex(np.array([]))[0].tz) == "US/Eastern"
|
46 | 46 |
|
| 47 | + def test_reindex_with_same_tz(self): |
| 48 | + # GH 32740 |
| 49 | + rng_a = date_range("2010-01-01", "2010-01-02", periods=24, tz="utc") |
| 50 | + rng_b = date_range("2010-01-01", "2010-01-02", periods=23, tz="utc") |
| 51 | + result1, result2 = rng_a.reindex( |
| 52 | + rng_b, method="nearest", tolerance=timedelta(seconds=20) |
| 53 | + ) |
| 54 | + expected_list1 = [ |
| 55 | + "2010-01-01 00:00:00", |
| 56 | + "2010-01-01 01:05:27.272727272", |
| 57 | + "2010-01-01 02:10:54.545454545", |
| 58 | + "2010-01-01 03:16:21.818181818", |
| 59 | + "2010-01-01 04:21:49.090909090", |
| 60 | + "2010-01-01 05:27:16.363636363", |
| 61 | + "2010-01-01 06:32:43.636363636", |
| 62 | + "2010-01-01 07:38:10.909090909", |
| 63 | + "2010-01-01 08:43:38.181818181", |
| 64 | + "2010-01-01 09:49:05.454545454", |
| 65 | + "2010-01-01 10:54:32.727272727", |
| 66 | + "2010-01-01 12:00:00", |
| 67 | + "2010-01-01 13:05:27.272727272", |
| 68 | + "2010-01-01 14:10:54.545454545", |
| 69 | + "2010-01-01 15:16:21.818181818", |
| 70 | + "2010-01-01 16:21:49.090909090", |
| 71 | + "2010-01-01 17:27:16.363636363", |
| 72 | + "2010-01-01 18:32:43.636363636", |
| 73 | + "2010-01-01 19:38:10.909090909", |
| 74 | + "2010-01-01 20:43:38.181818181", |
| 75 | + "2010-01-01 21:49:05.454545454", |
| 76 | + "2010-01-01 22:54:32.727272727", |
| 77 | + "2010-01-02 00:00:00", |
| 78 | + ] |
| 79 | + expected1 = DatetimeIndex( |
| 80 | + expected_list1, dtype="datetime64[ns, UTC]", freq=None, |
| 81 | + ) |
| 82 | + expected2 = np.array([0] + [-1] * 21 + [23], dtype=np.int64,) |
| 83 | + tm.assert_index_equal(result1, expected1) |
| 84 | + tm.assert_numpy_array_equal(result2, expected2) |
| 85 | + |
47 | 86 | def test_time_loc(self): # GH8667
|
48 | 87 | from datetime import time
|
49 | 88 | from pandas._libs.index import _SIZE_CUTOFF
|
|
0 commit comments