Skip to content

Commit 739a8de

Browse files
TST: add date range test for reindex case from GH-32740 (#33265)
* add test on date range timezone reindex * undo * fix * move code to datetime test * import timedelta * adding assertion the np array results * comply to coding standard * update * update * assert_numpy_array_equal * comply black format * format checking * white space * bleck
1 parent 8415f9b commit 739a8de

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

pandas/tests/indexes/datetimes/test_datetime.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import date
1+
from datetime import date, timedelta
22

33
import dateutil
44
import numpy as np
@@ -44,6 +44,45 @@ def test_reindex_preserves_tz_if_target_is_empty_list_or_array(self):
4444
assert str(index.reindex([])[0].tz) == "US/Eastern"
4545
assert str(index.reindex(np.array([]))[0].tz) == "US/Eastern"
4646

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+
4786
def test_time_loc(self): # GH8667
4887
from datetime import time
4988
from pandas._libs.index import _SIZE_CUTOFF

0 commit comments

Comments
 (0)