Skip to content

BUG: Setting timedelta column by index causes it to loss precision #23511

Closed
@icexelloss

Description

@icexelloss

Code Sample, a copy-pastable example if possible

dt1 = pd.Timedelta(0)
dt2 = pd.Timedelta(28767471428571405)
df = pd.DataFrame({'dt': pd.Series([dt1, dt2])})
df_copy = df.copy()
s = pd.Series([dt1])

expected = df['dt'].iloc[1].value
df.loc[[True, False]] = s
result = df['dt'].iloc[1].value

print(result)
#28767471428571404

Problem description

Setting a timedelta column by index causes it to be casted to double and back. Therefore, it will loss precision.

Expected Output

28767471428571405

Output of pd.show_versions()

0.23.4

[paste the output of pd.show_versions() here below this line]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesNumeric OperationsArithmetic, Comparison, and Logical operationsTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions