Skip to content

BUG: Resample downsampling return NaN #9527

Closed
@KevinLourd

Description

@KevinLourd

Pandas resample bugs when trying to resample a time serie with same size splits :

I have a time serie of size 10:

rng = pd.date_range('20130101',periods=10,freq='T')
ts=pd.Series(np.random.randn(len(rng)), index=rng)

print(ts)

2013-01-01 00:00:00   -1.811999
2013-01-01 00:01:00   -0.890837
2013-01-01 00:02:00   -0.363520
2013-01-01 00:03:00   -0.026245
2013-01-01 00:04:00    1.515072
2013-01-01 00:05:00    0.920129
2013-01-01 00:06:00   -0.125954
2013-01-01 00:07:00    0.588933
2013-01-01 00:08:00   -1.278408
2013-01-01 00:09:00   -0.172525
Freq: T, dtype: float64

When trying to resample in 8 equal parts it works fine:

length = 8

print(ts)
timeSpan = (ts.index[-1]-ts.index[0]+timedelta(minutes=1))
rule = int(timeSpan.total_seconds()/length)
tsNew=ts.resample(str(rule)+"S")

print(tsNew)

2013-01-01 00:00:00    0.124147
2013-01-01 00:01:15    0.558947
2013-01-01 00:02:30    0.076321
2013-01-01 00:03:45    0.178429
2013-01-01 00:05:00   -1.357948
2013-01-01 00:06:15    0.931305
2013-01-01 00:07:30    0.984052
2013-01-01 00:08:45   -1.758608
Freq: 75S, dtype: float64

But when tying to split into 9 parts there are nan arriving :

length = 9

print(ts)
timeSpan = (ts.index[-1]-ts.index[0]+timedelta(minutes=1))
rule = int(timeSpan.total_seconds()/length)
tsNew=ts.resample(str(rule)+"S")

print(tsNew)

2013-01-01 00:00:00   -0.264389
2013-01-01 00:01:06         NaN
2013-01-01 00:02:12         NaN
2013-01-01 00:03:18         NaN
2013-01-01 00:04:24         NaN
2013-01-01 00:05:30         NaN
2013-01-01 00:06:36         NaN
2013-01-01 00:07:42         NaN
2013-01-01 00:08:48         NaN
2013-01-01 00:09:54         NaN
Freq: 66S, dtype: float64

Do you have an idea how to solve this issue ?

PS: with length > 10 it doesn't works neither...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions