Skip to content

resample function gives 0s instead of NaNs #4291

Closed
@xzenggit

Description

@xzenggit

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions