Skip to content

Commit 9edac8c

Browse files
committed
TST GH34290
Test for dt.total_seconds() stores float with appending 0.00000000000001 fix
1 parent 53d3c45 commit 9edac8c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

pandas/tests/arrays/test_timedeltas.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from datetime import timedelta
1+
from datetime import (
2+
datetime,
3+
timedelta,
4+
)
25

36
import numpy as np
47
import pytest
@@ -67,6 +70,30 @@ def test_total_seconds(self, unit, tda):
6770
expected = tda_nano.total_seconds()
6871
tm.assert_numpy_array_equal(result, expected)
6972

73+
def test_series_total_seconds(self):
74+
# GH34290
75+
expected = float(15)
76+
out = pd.Series(
77+
[pd.Timestamp("2022-03-16 08:32:26"), pd.Timestamp("2022-03-16 08:32:41")]
78+
)
79+
80+
result = (out - out.iloc[0]).dt.total_seconds()[1]
81+
assert result == expected
82+
83+
def test_dateframe_total_seconds(self):
84+
# GH34290
85+
expected = float(120)
86+
data = {"start": datetime(2020, 1, 1, 12), "end": datetime(2020, 1, 1, 12, 2)}
87+
df = pd.DataFrame(data, index=[0])
88+
89+
# try to parse to pd.to_datetime
90+
df["end"] = pd.to_datetime(df["end"])
91+
df["start"] = pd.to_datetime(df["start"])
92+
93+
result = (df["end"] - df["start"]).dt.total_seconds().values[0]
94+
95+
assert result == expected
96+
7097
@pytest.mark.parametrize(
7198
"nat", [np.datetime64("NaT", "ns"), np.datetime64("NaT", "us")]
7299
)

0 commit comments

Comments
 (0)