Skip to content

BUG: Resample downsampling return NaN #9527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KevinLourd opened this issue Feb 19, 2015 · 2 comments
Closed

BUG: Resample downsampling return NaN #9527

KevinLourd opened this issue Feb 19, 2015 · 2 comments
Labels
Bug Resample resample method

Comments

@KevinLourd
Copy link

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...

@jreback
Copy link
Contributor

jreback commented Feb 19, 2015

pls pd.show_versions()

this was fixed by #8371

In [26]: ts.resample('75s')
Out[26]: 
2013-01-01 00:00:00   -0.693761
2013-01-01 00:01:15    1.288526
2013-01-01 00:02:30    0.257802
2013-01-01 00:03:45   -0.888985
2013-01-01 00:05:00   -0.285519
2013-01-01 00:06:15   -2.179303
2013-01-01 00:07:30   -2.747954
2013-01-01 00:08:45    0.786829
Freq: 75S, dtype: float64

In [27]: ts.resample('66s')
Out[27]: 
2013-01-01 00:00:00   -0.693761
2013-01-01 00:01:06    1.288526
2013-01-01 00:02:12    0.257802
2013-01-01 00:03:18   -0.888985
2013-01-01 00:04:24   -1.389829
2013-01-01 00:05:30    0.818791
2013-01-01 00:06:36   -2.179303
2013-01-01 00:07:42   -2.747954
2013-01-01 00:08:48    0.786829
Freq: 66S, dtype: float64

@jreback jreback closed this as completed Feb 19, 2015
@jreback jreback added Bug Resample resample method labels Feb 19, 2015
@KevinLourd
Copy link
Author

Thank you jreback.
I was in pandas: 0.14.1, issue solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Resample resample method
Projects
None yet
Development

No branches or pull requests

2 participants