pydata / pydata/xarray

DataArrray.resample() appears to ignore skipna parameter while taking annual mean

Open
#7,545 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-error reporting
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened?

The skipna parameter appears to have no effect while annually resampling a monthly DataArray.
I'm not sure if this is related to #6772

What did you expect to happen?

I expected da_yrA to be NaN since I am not skipping NaN values.

Minimal Complete Verifiable Example
import numpy as np
import pandas as pd
import xarray as xr

data = np.arange(12)
month_index = pd.date_range("2022-01","2022-12-31", freq="M")
df = pd.DataFrame(index=month_index, data=data)
df.index.name = "time"
df.columns.name = "value"
df.loc["2022-01":"2022-02"] = np.nan
da = xr.DataArray(df)

# these unexpectedly produce the same result
da_yrA = (da).resample(time="A-Dec", skipna=False).mean()
da_yrB = (da).resample(time="A-Dec", skipna=True).mean()

print(da_yrA)
print(da_yrB)
MVCE confirmation
  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
Relevant log output

No response

Anything else we need to know?

No response

Environment
scipy: 1.10.0
netCDF4: 1.6.2
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.6.2
nc_time_axis: 1.4.1
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2023.2.0
distributed: 2023.2.0
matplotlib: 3.7.0
cartopy: 0.21.1
seaborn: None
numbagg: None
fsspec: 2023.1.0
cupy: None
pint: None
sparse: 0.13.0
flox: None
numpy_groupies: None
setuptools: 67.3.2
pip: 23.0.1
conda: None
pytest: None
mypy: None
IPython: 8.10.0
sphinx: None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied MVCE and compare the annual resampling results for skipna=False and skipna=True. Trace the DataArray resampling mean path to determine where the parameter is handled, then add regression coverage showing that the non-skipping result is NaN while the skipping result is not.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.