Skip to content

TST: dt.total_seconds() stores float with appending 0.00000000000001 fix #48218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion pandas/tests/arrays/test_timedeltas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import timedelta
from datetime import (
datetime,
timedelta,
)

import numpy as np
import pytest
Expand Down Expand Up @@ -67,6 +70,30 @@ def test_total_seconds(self, unit, tda):
expected = tda_nano.total_seconds()
tm.assert_numpy_array_equal(result, expected)

def test_series_total_seconds(self):
# GH34290
expected = float(15)
out = pd.Series(
[pd.Timestamp("2022-03-16 08:32:26"), pd.Timestamp("2022-03-16 08:32:41")]
)

result = (out - out.iloc[0]).dt.total_seconds()[1]
assert result == expected

def test_dateframe_total_seconds(self):
# GH34290
expected = float(120)
data = {"start": datetime(2020, 1, 1, 12), "end": datetime(2020, 1, 1, 12, 2)}
df = pd.DataFrame(data, index=[0])

# try to parse to pd.to_datetime
df["end"] = pd.to_datetime(df["end"])
df["start"] = pd.to_datetime(df["start"])

result = (df["end"] - df["start"]).dt.total_seconds().values[0]

assert result == expected

@pytest.mark.parametrize(
"nat", [np.datetime64("NaT", "ns"), np.datetime64("NaT", "us")]
)
Expand Down