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/6808 below:

Bug when adding a timedelta to a datetime · Issue #6808 · pandas-dev/pandas · GitHub

Hello,

I wanted to add a specified offset (10 seconds) to and existing datetime (an index previously created by pd.to_datetime), so I thought creating a timedelta and adding it would do the trick. As you can see it doesn't yield an error but produces a rather strange results.

@buddha[J:T26]|5> base = pd.to_datetime(datetime.datetime.now())
@buddha[J:T26]|6> offset = pd.to_timedelta(10, unit='s')
@buddha[J:T26]|7> offset
              <7> numpy.timedelta64(10000000000,'ns')
@buddha[J:T26]|8> base
              <8> Timestamp('2014-04-05 13:13:40.374000', tz=None)
@buddha[J:T26]|9> base + offset
              <9> Timestamp('2014-04-05 13:13:41.784065408', tz=None)

If I try to do the same by creating a datetime.timedelta then everything works as expected.

@buddha[J:T26]|10> offset2 = datetime.timedelta(seconds = 10)
@buddha[J:T26]|11> base + offset2
              <11> Timestamp('2014-04-05 13:13:50.374000', tz=None)

This is really confusing and hard to spot. I think that pd.to_datetime and pd.to_timedelta should be compatible, but if they are not, please make the error easier to spot.

Thanks,
Adam


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