From f5177bd0f38c6423ba8c508a00c489d79752c869 Mon Sep 17 00:00:00 2001 From: valery Date: Tue, 18 Apr 2023 15:59:51 +0200 Subject: [PATCH] add test to reproduce bug in the issue #48521 --- pandas/tests/arrays/test_timedeltas.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/arrays/test_timedeltas.py b/pandas/tests/arrays/test_timedeltas.py index 69d92b1551e14..1043c2ee6c9b6 100644 --- a/pandas/tests/arrays/test_timedeltas.py +++ b/pandas/tests/arrays/test_timedeltas.py @@ -70,6 +70,14 @@ def test_timedelta_array_total_seconds(self): result = pd.array([Timedelta("2 min")]).total_seconds()[0] assert result == expected + def test_total_seconds_nanoseconds(self): + # issue #48521 + start_time = pd.Series(["2145-11-02 06:00:00"]).astype("datetime64[ns]") + end_time = pd.Series(["2145-11-02 07:06:00"]).astype("datetime64[ns]") + expected = (end_time - start_time).values / np.timedelta64(1, "s") + result = (end_time - start_time).dt.total_seconds().values + assert result == expected + @pytest.mark.parametrize( "nat", [np.datetime64("NaT", "ns"), np.datetime64("NaT", "us")] )