Skip to content

BUG: nested dict construction timedelta #11129

Closed
@chris-b1

Description

@chris-b1

Related to #10160 / PR #10269

In [2]: from datetime import timedelta
...: from pandas import * 
...: td_as_int = [1, 2, 3, 4]
...: 
...: def create_data(constructor):
...:     return dict((i, {constructor(s): 2*i}) for i, s in enumerate(td_as_int))
...: 
...: data_timedelta64 = create_data(lambda x: np.timedelta64(x, 'D'))
...: data_timedelta = create_data(lambda x: timedelta(days=x))
...: 
...: result_timedelta64 = DataFrame(data_timedelta64)
...: result_timedelta = DataFrame(data_timedelta)
...: 

In [3]: result_timedelta64
Out[3]: 
        0   1   2   3
1 days   0 NaN NaN NaN
2 days NaN   2 NaN NaN
3 days NaN NaN   4 NaN
4 days NaN NaN NaN   6

In [4]: result_timedelta
Out[4]: 
        0   1   2   3
1 days NaN NaN NaN NaN
2 days NaN NaN NaN NaN
3 days NaN NaN NaN NaN
4 days NaN NaN NaN NaN

This seems to happen because Timedelta doesn't have hash equality with datetime.timedelta It could easily be worked around here, but I was wondering if there's any reason not to make Timedelta work like Timestamp and match hashes if above a certain resolution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsReshapingConcat, Merge/Join, Stack/Unstack, ExplodeTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions