test_unary_ops.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. from datetime import datetime
  2. from dateutil.tz import gettz
  3. from hypothesis import (
  4. given,
  5. strategies as st,
  6. )
  7. import numpy as np
  8. import pytest
  9. import pytz
  10. from pytz import utc
  11. from pandas._libs import lib
  12. from pandas._libs.tslibs import (
  13. NaT,
  14. OutOfBoundsDatetime,
  15. Timedelta,
  16. Timestamp,
  17. conversion,
  18. iNaT,
  19. to_offset,
  20. )
  21. from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
  22. from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG
  23. import pandas.util._test_decorators as td
  24. import pandas._testing as tm
  25. class TestTimestampUnaryOps:
  26. # --------------------------------------------------------------
  27. def test_round_divison_by_zero_raises(self):
  28. ts = Timestamp("2016-01-01")
  29. msg = "Division by zero in rounding"
  30. with pytest.raises(ValueError, match=msg):
  31. ts.round("0ns")
  32. # Timestamp.round
  33. @pytest.mark.parametrize(
  34. "timestamp, freq, expected",
  35. [
  36. ("20130101 09:10:11", "D", "20130101"),
  37. ("20130101 19:10:11", "D", "20130102"),
  38. ("20130201 12:00:00", "D", "20130202"),
  39. ("20130104 12:00:00", "D", "20130105"),
  40. ("2000-01-05 05:09:15.13", "D", "2000-01-05 00:00:00"),
  41. ("2000-01-05 05:09:15.13", "H", "2000-01-05 05:00:00"),
  42. ("2000-01-05 05:09:15.13", "S", "2000-01-05 05:09:15"),
  43. ],
  44. )
  45. def test_round_frequencies(self, timestamp, freq, expected):
  46. dt = Timestamp(timestamp)
  47. result = dt.round(freq)
  48. expected = Timestamp(expected)
  49. assert result == expected
  50. def test_round_tzaware(self):
  51. dt = Timestamp("20130101 09:10:11", tz="US/Eastern")
  52. result = dt.round("D")
  53. expected = Timestamp("20130101", tz="US/Eastern")
  54. assert result == expected
  55. dt = Timestamp("20130101 09:10:11", tz="US/Eastern")
  56. result = dt.round("s")
  57. assert result == dt
  58. def test_round_30min(self):
  59. # round
  60. dt = Timestamp("20130104 12:32:00")
  61. result = dt.round("30Min")
  62. expected = Timestamp("20130104 12:30:00")
  63. assert result == expected
  64. def test_round_subsecond(self):
  65. # GH#14440 & GH#15578
  66. result = Timestamp("2016-10-17 12:00:00.0015").round("ms")
  67. expected = Timestamp("2016-10-17 12:00:00.002000")
  68. assert result == expected
  69. result = Timestamp("2016-10-17 12:00:00.00149").round("ms")
  70. expected = Timestamp("2016-10-17 12:00:00.001000")
  71. assert result == expected
  72. ts = Timestamp("2016-10-17 12:00:00.0015")
  73. for freq in ["us", "ns"]:
  74. assert ts == ts.round(freq)
  75. result = Timestamp("2016-10-17 12:00:00.001501031").round("10ns")
  76. expected = Timestamp("2016-10-17 12:00:00.001501030")
  77. assert result == expected
  78. def test_round_nonstandard_freq(self):
  79. with tm.assert_produces_warning(False):
  80. Timestamp("2016-10-17 12:00:00.001501031").round("1010ns")
  81. def test_round_invalid_arg(self):
  82. stamp = Timestamp("2000-01-05 05:09:15.13")
  83. with pytest.raises(ValueError, match=INVALID_FREQ_ERR_MSG):
  84. stamp.round("foo")
  85. @pytest.mark.parametrize(
  86. "test_input, rounder, freq, expected",
  87. [
  88. ("2117-01-01 00:00:45", "floor", "15s", "2117-01-01 00:00:45"),
  89. ("2117-01-01 00:00:45", "ceil", "15s", "2117-01-01 00:00:45"),
  90. (
  91. "2117-01-01 00:00:45.000000012",
  92. "floor",
  93. "10ns",
  94. "2117-01-01 00:00:45.000000010",
  95. ),
  96. (
  97. "1823-01-01 00:00:01.000000012",
  98. "ceil",
  99. "10ns",
  100. "1823-01-01 00:00:01.000000020",
  101. ),
  102. ("1823-01-01 00:00:01", "floor", "1s", "1823-01-01 00:00:01"),
  103. ("1823-01-01 00:00:01", "ceil", "1s", "1823-01-01 00:00:01"),
  104. ("NaT", "floor", "1s", "NaT"),
  105. ("NaT", "ceil", "1s", "NaT"),
  106. ],
  107. )
  108. def test_ceil_floor_edge(self, test_input, rounder, freq, expected):
  109. dt = Timestamp(test_input)
  110. func = getattr(dt, rounder)
  111. result = func(freq)
  112. if dt is NaT:
  113. assert result is NaT
  114. else:
  115. expected = Timestamp(expected)
  116. assert result == expected
  117. @pytest.mark.parametrize(
  118. "test_input, freq, expected",
  119. [
  120. ("2018-01-01 00:02:06", "2s", "2018-01-01 00:02:06"),
  121. ("2018-01-01 00:02:00", "2T", "2018-01-01 00:02:00"),
  122. ("2018-01-01 00:04:00", "4T", "2018-01-01 00:04:00"),
  123. ("2018-01-01 00:15:00", "15T", "2018-01-01 00:15:00"),
  124. ("2018-01-01 00:20:00", "20T", "2018-01-01 00:20:00"),
  125. ("2018-01-01 03:00:00", "3H", "2018-01-01 03:00:00"),
  126. ],
  127. )
  128. @pytest.mark.parametrize("rounder", ["ceil", "floor", "round"])
  129. def test_round_minute_freq(self, test_input, freq, expected, rounder):
  130. # Ensure timestamps that shouldn't round dont!
  131. # GH#21262
  132. dt = Timestamp(test_input)
  133. expected = Timestamp(expected)
  134. func = getattr(dt, rounder)
  135. result = func(freq)
  136. assert result == expected
  137. @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"])
  138. def test_ceil(self, unit):
  139. dt = Timestamp("20130101 09:10:11").as_unit(unit)
  140. result = dt.ceil("D")
  141. expected = Timestamp("20130102")
  142. assert result == expected
  143. assert result._creso == dt._creso
  144. @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"])
  145. def test_floor(self, unit):
  146. dt = Timestamp("20130101 09:10:11").as_unit(unit)
  147. result = dt.floor("D")
  148. expected = Timestamp("20130101")
  149. assert result == expected
  150. assert result._creso == dt._creso
  151. @pytest.mark.parametrize("method", ["ceil", "round", "floor"])
  152. @pytest.mark.parametrize(
  153. "unit",
  154. ["ns", "us", "ms", "s"],
  155. )
  156. def test_round_dst_border_ambiguous(self, method, unit):
  157. # GH 18946 round near "fall back" DST
  158. ts = Timestamp("2017-10-29 00:00:00", tz="UTC").tz_convert("Europe/Madrid")
  159. ts = ts.as_unit(unit)
  160. #
  161. result = getattr(ts, method)("H", ambiguous=True)
  162. assert result == ts
  163. assert result._creso == getattr(NpyDatetimeUnit, f"NPY_FR_{unit}").value
  164. result = getattr(ts, method)("H", ambiguous=False)
  165. expected = Timestamp("2017-10-29 01:00:00", tz="UTC").tz_convert(
  166. "Europe/Madrid"
  167. )
  168. assert result == expected
  169. assert result._creso == getattr(NpyDatetimeUnit, f"NPY_FR_{unit}").value
  170. result = getattr(ts, method)("H", ambiguous="NaT")
  171. assert result is NaT
  172. msg = "Cannot infer dst time"
  173. with pytest.raises(pytz.AmbiguousTimeError, match=msg):
  174. getattr(ts, method)("H", ambiguous="raise")
  175. @pytest.mark.parametrize(
  176. "method, ts_str, freq",
  177. [
  178. ["ceil", "2018-03-11 01:59:00-0600", "5min"],
  179. ["round", "2018-03-11 01:59:00-0600", "5min"],
  180. ["floor", "2018-03-11 03:01:00-0500", "2H"],
  181. ],
  182. )
  183. @pytest.mark.parametrize(
  184. "unit",
  185. ["ns", "us", "ms", "s"],
  186. )
  187. def test_round_dst_border_nonexistent(self, method, ts_str, freq, unit):
  188. # GH 23324 round near "spring forward" DST
  189. ts = Timestamp(ts_str, tz="America/Chicago").as_unit(unit)
  190. result = getattr(ts, method)(freq, nonexistent="shift_forward")
  191. expected = Timestamp("2018-03-11 03:00:00", tz="America/Chicago")
  192. assert result == expected
  193. assert result._creso == getattr(NpyDatetimeUnit, f"NPY_FR_{unit}").value
  194. result = getattr(ts, method)(freq, nonexistent="NaT")
  195. assert result is NaT
  196. msg = "2018-03-11 02:00:00"
  197. with pytest.raises(pytz.NonExistentTimeError, match=msg):
  198. getattr(ts, method)(freq, nonexistent="raise")
  199. @pytest.mark.parametrize(
  200. "timestamp",
  201. [
  202. "2018-01-01 0:0:0.124999360",
  203. "2018-01-01 0:0:0.125000367",
  204. "2018-01-01 0:0:0.125500",
  205. "2018-01-01 0:0:0.126500",
  206. "2018-01-01 12:00:00",
  207. "2019-01-01 12:00:00",
  208. ],
  209. )
  210. @pytest.mark.parametrize(
  211. "freq",
  212. [
  213. "2ns",
  214. "3ns",
  215. "4ns",
  216. "5ns",
  217. "6ns",
  218. "7ns",
  219. "250ns",
  220. "500ns",
  221. "750ns",
  222. "1us",
  223. "19us",
  224. "250us",
  225. "500us",
  226. "750us",
  227. "1s",
  228. "2s",
  229. "3s",
  230. "1D",
  231. ],
  232. )
  233. def test_round_int64(self, timestamp, freq):
  234. # check that all rounding modes are accurate to int64 precision
  235. # see GH#22591
  236. dt = Timestamp(timestamp).as_unit("ns")
  237. unit = to_offset(freq).nanos
  238. # test floor
  239. result = dt.floor(freq)
  240. assert result._value % unit == 0, f"floor not a {freq} multiple"
  241. assert 0 <= dt._value - result._value < unit, "floor error"
  242. # test ceil
  243. result = dt.ceil(freq)
  244. assert result._value % unit == 0, f"ceil not a {freq} multiple"
  245. assert 0 <= result._value - dt._value < unit, "ceil error"
  246. # test round
  247. result = dt.round(freq)
  248. assert result._value % unit == 0, f"round not a {freq} multiple"
  249. assert abs(result._value - dt._value) <= unit // 2, "round error"
  250. if unit % 2 == 0 and abs(result._value - dt._value) == unit // 2:
  251. # round half to even
  252. assert result._value // unit % 2 == 0, "round half to even error"
  253. def test_round_implementation_bounds(self):
  254. # See also: analogous test for Timedelta
  255. result = Timestamp.min.ceil("s")
  256. expected = Timestamp(1677, 9, 21, 0, 12, 44)
  257. assert result == expected
  258. result = Timestamp.max.floor("s")
  259. expected = Timestamp.max - Timedelta(854775807)
  260. assert result == expected
  261. with pytest.raises(OverflowError, match="value too large"):
  262. Timestamp.min.floor("s")
  263. # the second message here shows up in windows builds
  264. msg = "|".join(
  265. ["Python int too large to convert to C long", "int too big to convert"]
  266. )
  267. with pytest.raises(OverflowError, match=msg):
  268. Timestamp.max.ceil("s")
  269. @pytest.mark.xfail(reason="Failing on builds", strict=False)
  270. @given(val=st.integers(iNaT + 1, lib.i8max))
  271. @pytest.mark.parametrize(
  272. "method", [Timestamp.round, Timestamp.floor, Timestamp.ceil]
  273. )
  274. def test_round_sanity(self, val, method):
  275. val = np.int64(val)
  276. ts = Timestamp(val)
  277. def checker(res, ts, nanos):
  278. if method is Timestamp.round:
  279. diff = np.abs((res - ts)._value)
  280. assert diff <= nanos / 2
  281. elif method is Timestamp.floor:
  282. assert res <= ts
  283. elif method is Timestamp.ceil:
  284. assert res >= ts
  285. assert method(ts, "ns") == ts
  286. res = method(ts, "us")
  287. nanos = 1000
  288. assert np.abs((res - ts)._value) < nanos
  289. assert res._value % nanos == 0
  290. checker(res, ts, nanos)
  291. res = method(ts, "ms")
  292. nanos = 1_000_000
  293. assert np.abs((res - ts)._value) < nanos
  294. assert res._value % nanos == 0
  295. checker(res, ts, nanos)
  296. res = method(ts, "s")
  297. nanos = 1_000_000_000
  298. assert np.abs((res - ts)._value) < nanos
  299. assert res._value % nanos == 0
  300. checker(res, ts, nanos)
  301. res = method(ts, "min")
  302. nanos = 60 * 1_000_000_000
  303. assert np.abs((res - ts)._value) < nanos
  304. assert res._value % nanos == 0
  305. checker(res, ts, nanos)
  306. res = method(ts, "h")
  307. nanos = 60 * 60 * 1_000_000_000
  308. assert np.abs((res - ts)._value) < nanos
  309. assert res._value % nanos == 0
  310. checker(res, ts, nanos)
  311. res = method(ts, "D")
  312. nanos = 24 * 60 * 60 * 1_000_000_000
  313. assert np.abs((res - ts)._value) < nanos
  314. assert res._value % nanos == 0
  315. checker(res, ts, nanos)
  316. # --------------------------------------------------------------
  317. # Timestamp.replace
  318. def test_replace_out_of_pydatetime_bounds(self):
  319. # GH#50348
  320. ts = Timestamp("2016-01-01").as_unit("ns")
  321. msg = "Out of bounds nanosecond timestamp: 99999-01-01 00:00:00"
  322. with pytest.raises(OutOfBoundsDatetime, match=msg):
  323. ts.replace(year=99_999)
  324. ts = ts.as_unit("ms")
  325. result = ts.replace(year=99_999)
  326. assert result.year == 99_999
  327. assert result._value == Timestamp(np.datetime64("99999-01-01", "ms"))._value
  328. def test_replace_non_nano(self):
  329. ts = Timestamp._from_value_and_reso(
  330. 91514880000000000, NpyDatetimeUnit.NPY_FR_us.value, None
  331. )
  332. assert ts.to_pydatetime() == datetime(4869, 12, 28)
  333. result = ts.replace(year=4900)
  334. assert result._creso == ts._creso
  335. assert result.to_pydatetime() == datetime(4900, 12, 28)
  336. def test_replace_naive(self):
  337. # GH#14621, GH#7825
  338. ts = Timestamp("2016-01-01 09:00:00")
  339. result = ts.replace(hour=0)
  340. expected = Timestamp("2016-01-01 00:00:00")
  341. assert result == expected
  342. def test_replace_aware(self, tz_aware_fixture):
  343. tz = tz_aware_fixture
  344. # GH#14621, GH#7825
  345. # replacing datetime components with and w/o presence of a timezone
  346. ts = Timestamp("2016-01-01 09:00:00", tz=tz)
  347. result = ts.replace(hour=0)
  348. expected = Timestamp("2016-01-01 00:00:00", tz=tz)
  349. assert result == expected
  350. def test_replace_preserves_nanos(self, tz_aware_fixture):
  351. tz = tz_aware_fixture
  352. # GH#14621, GH#7825
  353. ts = Timestamp("2016-01-01 09:00:00.000000123", tz=tz)
  354. result = ts.replace(hour=0)
  355. expected = Timestamp("2016-01-01 00:00:00.000000123", tz=tz)
  356. assert result == expected
  357. def test_replace_multiple(self, tz_aware_fixture):
  358. tz = tz_aware_fixture
  359. # GH#14621, GH#7825
  360. # replacing datetime components with and w/o presence of a timezone
  361. # test all
  362. ts = Timestamp("2016-01-01 09:00:00.000000123", tz=tz)
  363. result = ts.replace(
  364. year=2015,
  365. month=2,
  366. day=2,
  367. hour=0,
  368. minute=5,
  369. second=5,
  370. microsecond=5,
  371. nanosecond=5,
  372. )
  373. expected = Timestamp("2015-02-02 00:05:05.000005005", tz=tz)
  374. assert result == expected
  375. def test_replace_invalid_kwarg(self, tz_aware_fixture):
  376. tz = tz_aware_fixture
  377. # GH#14621, GH#7825
  378. ts = Timestamp("2016-01-01 09:00:00.000000123", tz=tz)
  379. msg = r"replace\(\) got an unexpected keyword argument"
  380. with pytest.raises(TypeError, match=msg):
  381. ts.replace(foo=5)
  382. def test_replace_integer_args(self, tz_aware_fixture):
  383. tz = tz_aware_fixture
  384. # GH#14621, GH#7825
  385. ts = Timestamp("2016-01-01 09:00:00.000000123", tz=tz)
  386. msg = "value must be an integer, received <class 'float'> for hour"
  387. with pytest.raises(ValueError, match=msg):
  388. ts.replace(hour=0.1)
  389. def test_replace_tzinfo_equiv_tz_localize_none(self):
  390. # GH#14621, GH#7825
  391. # assert conversion to naive is the same as replacing tzinfo with None
  392. ts = Timestamp("2013-11-03 01:59:59.999999-0400", tz="US/Eastern")
  393. assert ts.tz_localize(None) == ts.replace(tzinfo=None)
  394. @td.skip_if_windows
  395. def test_replace_tzinfo(self):
  396. # GH#15683
  397. dt = datetime(2016, 3, 27, 1)
  398. tzinfo = pytz.timezone("CET").localize(dt, is_dst=False).tzinfo
  399. result_dt = dt.replace(tzinfo=tzinfo)
  400. result_pd = Timestamp(dt).replace(tzinfo=tzinfo)
  401. # datetime.timestamp() converts in the local timezone
  402. with tm.set_timezone("UTC"):
  403. assert result_dt.timestamp() == result_pd.timestamp()
  404. assert result_dt == result_pd
  405. assert result_dt == result_pd.to_pydatetime()
  406. result_dt = dt.replace(tzinfo=tzinfo).replace(tzinfo=None)
  407. result_pd = Timestamp(dt).replace(tzinfo=tzinfo).replace(tzinfo=None)
  408. # datetime.timestamp() converts in the local timezone
  409. with tm.set_timezone("UTC"):
  410. assert result_dt.timestamp() == result_pd.timestamp()
  411. assert result_dt == result_pd
  412. assert result_dt == result_pd.to_pydatetime()
  413. @pytest.mark.parametrize(
  414. "tz, normalize",
  415. [
  416. (pytz.timezone("US/Eastern"), lambda x: x.tzinfo.normalize(x)),
  417. (gettz("US/Eastern"), lambda x: x),
  418. ],
  419. )
  420. def test_replace_across_dst(self, tz, normalize):
  421. # GH#18319 check that 1) timezone is correctly normalized and
  422. # 2) that hour is not incorrectly changed by this normalization
  423. ts_naive = Timestamp("2017-12-03 16:03:30")
  424. ts_aware = conversion.localize_pydatetime(ts_naive, tz)
  425. # Preliminary sanity-check
  426. assert ts_aware == normalize(ts_aware)
  427. # Replace across DST boundary
  428. ts2 = ts_aware.replace(month=6)
  429. # Check that `replace` preserves hour literal
  430. assert (ts2.hour, ts2.minute) == (ts_aware.hour, ts_aware.minute)
  431. # Check that post-replace object is appropriately normalized
  432. ts2b = normalize(ts2)
  433. assert ts2 == ts2b
  434. @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"])
  435. def test_replace_dst_border(self, unit):
  436. # Gh 7825
  437. t = Timestamp("2013-11-3", tz="America/Chicago").as_unit(unit)
  438. result = t.replace(hour=3)
  439. expected = Timestamp("2013-11-3 03:00:00", tz="America/Chicago")
  440. assert result == expected
  441. assert result._creso == getattr(NpyDatetimeUnit, f"NPY_FR_{unit}").value
  442. @pytest.mark.parametrize("fold", [0, 1])
  443. @pytest.mark.parametrize("tz", ["dateutil/Europe/London", "Europe/London"])
  444. @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"])
  445. def test_replace_dst_fold(self, fold, tz, unit):
  446. # GH 25017
  447. d = datetime(2019, 10, 27, 2, 30)
  448. ts = Timestamp(d, tz=tz).as_unit(unit)
  449. result = ts.replace(hour=1, fold=fold)
  450. expected = Timestamp(datetime(2019, 10, 27, 1, 30)).tz_localize(
  451. tz, ambiguous=not fold
  452. )
  453. assert result == expected
  454. assert result._creso == getattr(NpyDatetimeUnit, f"NPY_FR_{unit}").value
  455. # --------------------------------------------------------------
  456. # Timestamp.normalize
  457. @pytest.mark.parametrize("arg", ["2013-11-30", "2013-11-30 12:00:00"])
  458. @pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"])
  459. def test_normalize(self, tz_naive_fixture, arg, unit):
  460. tz = tz_naive_fixture
  461. ts = Timestamp(arg, tz=tz).as_unit(unit)
  462. result = ts.normalize()
  463. expected = Timestamp("2013-11-30", tz=tz)
  464. assert result == expected
  465. assert result._creso == getattr(NpyDatetimeUnit, f"NPY_FR_{unit}").value
  466. def test_normalize_pre_epoch_dates(self):
  467. # GH: 36294
  468. result = Timestamp("1969-01-01 09:00:00").normalize()
  469. expected = Timestamp("1969-01-01 00:00:00")
  470. assert result == expected
  471. # --------------------------------------------------------------
  472. @td.skip_if_windows
  473. def test_timestamp(self, fixed_now_ts):
  474. # GH#17329
  475. # tz-naive --> treat it as if it were UTC for purposes of timestamp()
  476. ts = fixed_now_ts
  477. uts = ts.replace(tzinfo=utc)
  478. assert ts.timestamp() == uts.timestamp()
  479. tsc = Timestamp("2014-10-11 11:00:01.12345678", tz="US/Central")
  480. utsc = tsc.tz_convert("UTC")
  481. # utsc is a different representation of the same time
  482. assert tsc.timestamp() == utsc.timestamp()
  483. # datetime.timestamp() converts in the local timezone
  484. with tm.set_timezone("UTC"):
  485. # should agree with datetime.timestamp method
  486. dt = ts.to_pydatetime()
  487. assert dt.timestamp() == ts.timestamp()
  488. @pytest.mark.parametrize("fold", [0, 1])
  489. def test_replace_preserves_fold(fold):
  490. # GH 37610. Check that replace preserves Timestamp fold property
  491. tz = gettz("Europe/Moscow")
  492. ts = Timestamp(year=2009, month=10, day=25, hour=2, minute=30, fold=fold, tzinfo=tz)
  493. ts_replaced = ts.replace(second=1)
  494. assert ts_replaced.fold == fold