A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/11129 below:

nested dict construction timedelta · Issue #11129 · pandas-dev/pandas · GitHub

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?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4