Skip to content

Implement CFPeriodIndex #2481

Closed
Closed
@huard

Description

@huard

A CFPeriodIndex supporting non-standard calendars would be useful to facilitate climate analyses. The use case for me would be to find the start and end date of a resampling group. This is useful to spot missing values in a resampled time series, or to create time_bnds arrays in a netCDF file.

import xarray as xr
import pandas as pd

cftime = xr.cftime_range(start='2000-01-01', periods=361, freq='D', calendar='360_day') 
pdtime = pd.date_range(start='2000-01-01', periods=361, freq='D')  

cf_da = xr.DataArray(range(361), coords={'time': cftime}, dims='time')
pd_da = xr.DataArray(range(361), coords={'time': pdtime}, dims='time') 

#cf_c = cf_da.resample(time='M').count()
pd_c = pd_da.resample(time='M').count()

#cf_p = cf_c.indexes['time'].to_period()
pd_p = pd_c.indexes['time'].to_period()

#cf_expected_days_in_group = cf_p.end_time - cf_p.start_time + pd.offsets.Day(1)
pd_expected_days_in_group = pd_p.end_time - pd_p.start_time + pd.offsets.Day(1)

Depends on #2191

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions