Question: I try to obtain day deltas for a wide range of pandas dates. However, for time deltas >292 years I obtain negative values. For example,

```
import pandas as pd
dates = pd.Series(pd.date_range('1700-01-01', periods=4500, freq='m'))
days_delta = (dates-dates.min()).astype('timedelta64[D]')

```

However, using a DatetimeIndex I can do it and it works as I want it to,

```
import pandas as pd
import numpy as np
dates = pd.date_range('1700-01-01', periods=4500, freq='m')
days_fun = np.vectorize(lambda x: x.days)
days_delta = days_fun(dates.date - dates.date.min())

```

The question then is how to obtain the correct days\_delta for Series objects?

Answer: 
Read [here](http://pandas.pydata.org/pandas-docs/stable/timedeltas.html#timedelta-limitations) specifically about timedelta limitations:

> 
> Pandas represents Timedeltas in nanosecond resolution using 64 bit integers. As such, the 64 bit integer limits determine the Timedelta limits.
> 
> 
> 

Incidentally this is the same limitation the docs mentioned that is placed on Timestamps in Pandas:

> 
> Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit integer is limited to approximately 584 years
> 
> 
> 

This would suggest that the same recommendations the docs make for circumventing the timestamp limitations can be applied to timedeltas. The solution to the timestamp limitations are found in the docs ([here](http://pandas.pydata.org/pandas-docs/stable/timeseries.html#representing-out-of-bounds-spans)):

> 
> If you have data that is outside of the Timestamp bounds, see Timestamp limitations, then you can use a PeriodIndex and/or Series of Periods to do computations.
> 
> 
>
Workaround
==========

If you have continuous dates with small gaps which are calculatable, as in your example, you could sort the series and then use `cumsum` to get around this problem, like this:

```
import pandas as pd
dates = pd.TimeSeries(pd.date_range('1700-01-01', periods=4500, freq='m'))
dates.sort()
dateshift = dates.shift(1)
(dates - dateshift).fillna(0).dt.days.cumsum().describe()

count      4500.000000
mean      68466.072444
std       39543.094524
min           0.000000
25%       34233.250000
50%       68465.500000
75%      102699.500000
max      136935.000000
dtype: float64

```

See the min and max are both positive.

Failaround
==========

If you have too big gaps, this workaround with not work. Like here:

```
dates = pd.Series(pd.datetools.to_datetime(['2016-06-06', '1700-01-01','2200-01-01']))
dates.sort()
dateshift = dates.shift(1)
(dates - dateshift).fillna(0).dt.days.cumsum()

1        0
0   -97931
2   -30883

```

This is because we calculate the step between each date, then add them up. And when they are sorted, we are guaranteed the smallest possible steps, however, each step is too big to handle in this case.

Resetting the order
-------------------

As you see in the **Failaround** example, the series is no longer ordered by the index. Fix this by calling the `.reset_index(inplace=True)` method on the series.