0

I have a pandas DatetimeIndex and I want to append infinity to the end, because I want to use it to make bins - with pandas.cut(..., right=False) - and I want the last bin to have infinity as an upper limit. Thus, I can later map whatever date exists after the last indexed date to the last bin. Of course, I don't know how a infinity timestamp whould look like, or if there is any. I am open to suggestions that can represent infinity in that context. If I am not articulate it clearly, please ask for any further explatations.

Example:

import pandas as pd
import numpy as np


dates = pd.DatetimeIndex(
    ['2007-03-01', '2007-06-01', '2008-09-01', '2010-04-01'],
    dtype='datetime64[ns]', freq=None
)

I am looking for something like:

dates = dates.append(pd.DatetimeIndex([np.inf]))

Of course the next one would work:

dates = dates.append(pd.DatetimeIndex(['3019-10-05']))

but, maybe someone wants to use it after 1000 years!

Also, is there a more efficient solution instead of append(), which makes a deep copy?

Thanks!

Thanasis Mattas
  • 484
  • 4
  • 16

1 Answers1

0

Actually, a solution would be appending pd.Timestamp.max

dates = dates.append(pd.DatetimeIndex([pd.Timestamp.max]))

Result:

DatetimeIndex([        '2007-03-01 00:00:00',  
                       '2007-06-01 00:00:00',  
                       '2008-09-01 00:00:00',  
                       '2010-04-01 00:00:00',  
             '2262-04-11 23:47:16.854775807'],  
            dtype='datetime64[ns]', freq=None)
Thanasis Mattas
  • 484
  • 4
  • 16