Skip to content

Resampling daily input data to half-yearly data generates an excessive time coordinate #2787

Closed
@grassland-curing-cfa

Description

@grassland-curing-cfa

Code Sample, a copy-pastable example if possible

A "Minimal, Complete and Verifiable Example" will make it much easier for maintainers to help you:
http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports

# Your code here
import numpy as np
import pandas as pd
import xarray as xr

time = pd.date_range('1972-01-01', freq='D', periods=366)    # a leap year
ds = xr.Dataset({'foo': ('time', np.arange(366)), 'time': time})

# Resample ds to every 6 months
res = ds['foo'].resample(time='6MS', closed='left').sum('time')
print(res)

Problem description

<xarray.DataArray 'foo' (time: 3)>
array([16471., 50324., nan])
Coordinates:

  • time (time) datetime64[ns] 1972-01-01 1972-07-01 1973-01-01

An excessive time coordinate of 1973-01-01 was generated despite the variable values being nan.

Expected Output

<xarray.DataArray 'foo' (time: 2)>
array([16471., 50324.])
Coordinates:

  • time (time) datetime64[ns] 1972-01-01 1972-07-01

Output of xr.show_versions()

# Paste the output here xr.show_versions() here

python: 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 2012ServerR2
machine: AMD64
processor: Intel64 Family 6 Model 47 Stepping 2, GenuineIntel

xarray: 0.11.2
pandas: 0.23.4
numpy: 1.16.0
scipy: 1.2.0
netCDF4: 1.4.2

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