Skip to content

resample function gives 0s instead of NaNs #4291

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
xzenggit opened this issue Jul 30, 2020 · 3 comments
Closed

resample function gives 0s instead of NaNs #4291

xzenggit opened this issue Jul 30, 2020 · 3 comments

Comments

@xzenggit
Copy link

xzenggit commented Jul 30, 2020

What happened:
When I use resample(time='1d').sum(dim='time') to resample a time series with NaNs, the resampled result gives me 0s instead of NaNs, while NaNs should be the correct answer.

What you expected to happen:

NaNs should be the correct answer.

Minimal Complete Verifiable Example:

import xarray as xr

dates =  pd.date_range('20200101', '20200601', freq='h')
data = np.linspace(0, 10, num=len(dates))
data[0:30*24] = np.nan

da = xr.DataArray(data, coords=[dates], dims='time')
da.plot()

# Instead of NaNs, the resampled time series in January 20202 give us 0s, which not right.
da.resample(time='1d', skipna=True).sum(dim='time', skipna=True).plot()

Anything else we need to know?:

Did I misunderstand something here? Thanks!

Environment:
xarray - '0.15.1'

Output of xr.show_versions()

xarray - '0.15.1'

@max-sixty
Copy link
Collaborator

max-sixty commented Jul 30, 2020

I agree this isn't that clear. I think min_count will solve this.

In [20]: da.resample(time='1d').sum(min_count=1)
Out[20]:
<xarray.DataArray (time: 153)>
array([         nan,          nan,          nan,          nan,
                nan,          nan,          nan,          nan,
                nan,          nan,          nan,          nan,

IIRC this mirrors pandas, would be keen to know if that's not the case

@xzenggit
Copy link
Author

Thanks. It'll make more sense if the default value of min_count is 1 instead of 0.

@max-sixty
Copy link
Collaborator

Yes, IIRC there have been extensive discussion about this over at pandas.

To the the extent there's anything that doesn't pandas' convention, please let us know, that wouldn't be intentional.

I'll close this for now but please reopen with any other questions. Thanks for raising @xzenggit .

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

No branches or pull requests

2 participants