{"head_branch": "cumulative", "contributor": "max-sixty", "sha_fail": "0ef192072cb4433dbc4524dee1041eadc20d086a", "sha_success": "bc99a661d07d7a33a6f95db78e9fdbfa22939c88", "language": "Python", "repo_owner": "pydata", "repo_name": "xarray", "workflow_name": "CI Additional", "workflow_filename": "ci-additional.yaml", "workflow_path": ".github/workflows/ci-additional.yaml", "workflow": "name: CI Additional\non:\n push:\n branches:\n - \"main\"\n pull_request:\n branches:\n - \"main\"\n workflow_dispatch: # allows you to trigger manually\n\nconcurrency:\n group: ${{ github.workflow }}-${{ github.ref }}\n cancel-in-progress: true\n\njobs:\n detect-ci-trigger:\n name: detect ci trigger\n runs-on: ubuntu-latest\n if: |\n github.repository == 'pydata/xarray'\n && (github.event_name == 'push' || github.event_name == 'pull_request')\n outputs:\n triggered: ${{ steps.detect-trigger.outputs.trigger-found }}\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 2\n - uses: xarray-contrib/ci-trigger@v1\n id: detect-trigger\n with:\n keyword: \"[skip-ci]\"\n\n doctest:\n name: Doctests\n runs-on: \"ubuntu-latest\"\n needs: detect-ci-trigger\n if: needs.detect-ci-trigger.outputs.triggered == 'false'\n defaults:\n run:\n shell: bash -l {0}\n\n env:\n CONDA_ENV_FILE: ci/requirements/environment.yml\n PYTHON_VERSION: \"3.11\"\n\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 0 # Fetch all history for all branches and tags.\n\n - name: set environment variables\n run: |\n echo \"TODAY=$(date +'%Y-%m-%d')\" >> $GITHUB_ENV\n\n - name: Setup micromamba\n uses: mamba-org/setup-micromamba@v1\n with:\n environment-file: ${{env.CONDA_ENV_FILE}}\n environment-name: xarray-tests\n create-args: >-\n python=${{env.PYTHON_VERSION}}\n conda\n cache-environment: true\n cache-environment-key: \"${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}\"\n\n - name: Install xarray\n run: |\n python -m pip install --no-deps -e .\n - name: Version info\n run: |\n conda info -a\n conda list\n python xarray/util/print_versions.py\n - name: Run doctests\n run: |\n # Raise an error if there are warnings in the doctests, with `-Werror`.\n # This is a trial; if it presents an problem, feel free to remove.\n # See https://github.com/pydata/xarray/issues/7164 for more info.\n python -m pytest --doctest-modules xarray --ignore xarray/tests -Werror\n\n mypy:\n name: Mypy\n runs-on: \"ubuntu-latest\"\n needs: detect-ci-trigger\n defaults:\n run:\n shell: bash -l {0}\n env:\n CONDA_ENV_FILE: ci/requirements/environment.yml\n PYTHON_VERSION: \"3.11\"\n\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 0 # Fetch all history for all branches and tags.\n\n - name: set environment variables\n run: |\n echo \"TODAY=$(date +'%Y-%m-%d')\" >> $GITHUB_ENV\n - name: Setup micromamba\n uses: mamba-org/setup-micromamba@v1\n with:\n environment-file: ${{env.CONDA_ENV_FILE}}\n environment-name: xarray-tests\n create-args: >-\n python=${{env.PYTHON_VERSION}}\n conda\n cache-environment: true\n cache-environment-key: \"${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}\"\n - name: Install xarray\n run: |\n python -m pip install --no-deps -e .\n - name: Version info\n run: |\n conda info -a\n conda list\n python xarray/util/print_versions.py\n - name: Install mypy\n run: |\n python -m pip install \"mypy<1.8\" --force-reinstall\n\n - name: Run mypy\n run: |\n python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report xarray/\n\n - name: Upload mypy coverage to Codecov\n uses: codecov/codecov-action@v3.1.4\n with:\n file: mypy_report/cobertura.xml\n flags: mypy\n env_vars: PYTHON_VERSION\n name: codecov-umbrella\n fail_ci_if_error: false\n\n mypy39:\n name: Mypy 3.9\n runs-on: \"ubuntu-latest\"\n needs: detect-ci-trigger\n defaults:\n run:\n shell: bash -l {0}\n env:\n CONDA_ENV_FILE: ci/requirements/environment.yml\n PYTHON_VERSION: \"3.9\"\n\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 0 # Fetch all history for all branches and tags.\n\n - name: set environment variables\n run: |\n echo \"TODAY=$(date +'%Y-%m-%d')\" >> $GITHUB_ENV\n - name: Setup micromamba\n uses: mamba-org/setup-micromamba@v1\n with:\n environment-file: ${{env.CONDA_ENV_FILE}}\n environment-name: xarray-tests\n create-args: >-\n python=${{env.PYTHON_VERSION}}\n conda\n cache-environment: true\n cache-environment-key: \"${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}\"\n - name: Install xarray\n run: |\n python -m pip install --no-deps -e .\n - name: Version info\n run: |\n conda info -a\n conda list\n python xarray/util/print_versions.py\n - name: Install mypy\n run: |\n python -m pip install \"mypy<1.8\" --force-reinstall\n\n - name: Run mypy\n run: |\n python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report xarray/\n\n - name: Upload mypy coverage to Codecov\n uses: codecov/codecov-action@v3.1.4\n with:\n file: mypy_report/cobertura.xml\n flags: mypy39\n env_vars: PYTHON_VERSION\n name: codecov-umbrella\n fail_ci_if_error: false\n\n\n\n pyright:\n name: Pyright\n runs-on: \"ubuntu-latest\"\n needs: detect-ci-trigger\n if: |\n always()\n && (\n contains( github.event.pull_request.labels.*.name, 'run-pyright')\n )\n defaults:\n run:\n shell: bash -l {0}\n env:\n CONDA_ENV_FILE: ci/requirements/environment.yml\n PYTHON_VERSION: \"3.10\"\n\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 0 # Fetch all history for all branches and tags.\n\n - name: set environment variables\n run: |\n echo \"TODAY=$(date +'%Y-%m-%d')\" >> $GITHUB_ENV\n - name: Setup micromamba\n uses: mamba-org/setup-micromamba@v1\n with:\n environment-file: ${{env.CONDA_ENV_FILE}}\n environment-name: xarray-tests\n create-args: >-\n python=${{env.PYTHON_VERSION}}\n conda\n cache-environment: true\n cache-environment-key: \"${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}\"\n - name: Install xarray\n run: |\n python -m pip install --no-deps -e .\n - name: Version info\n run: |\n conda info -a\n conda list\n python xarray/util/print_versions.py\n - name: Install pyright\n run: |\n python -m pip install pyright --force-reinstall\n\n - name: Run pyright\n run: |\n python -m pyright xarray/\n\n - name: Upload pyright coverage to Codecov\n uses: codecov/codecov-action@v3.1.4\n with:\n file: pyright_report/cobertura.xml\n flags: pyright\n env_vars: PYTHON_VERSION\n name: codecov-umbrella\n fail_ci_if_error: false\n\n pyright39:\n name: Pyright 3.9\n runs-on: \"ubuntu-latest\"\n needs: detect-ci-trigger\n if: |\n always()\n && (\n contains( github.event.pull_request.labels.*.name, 'run-pyright')\n )\n defaults:\n run:\n shell: bash -l {0}\n env:\n CONDA_ENV_FILE: ci/requirements/environment.yml\n PYTHON_VERSION: \"3.9\"\n\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 0 # Fetch all history for all branches and tags.\n\n - name: set environment variables\n run: |\n echo \"TODAY=$(date +'%Y-%m-%d')\" >> $GITHUB_ENV\n - name: Setup micromamba\n uses: mamba-org/setup-micromamba@v1\n with:\n environment-file: ${{env.CONDA_ENV_FILE}}\n environment-name: xarray-tests\n create-args: >-\n python=${{env.PYTHON_VERSION}}\n conda\n cache-environment: true\n cache-environment-key: \"${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}\"\n - name: Install xarray\n run: |\n python -m pip install --no-deps -e .\n - name: Version info\n run: |\n conda info -a\n conda list\n python xarray/util/print_versions.py\n - name: Install pyright\n run: |\n python -m pip install pyright --force-reinstall\n\n - name: Run pyright\n run: |\n python -m pyright xarray/\n\n - name: Upload pyright coverage to Codecov\n uses: codecov/codecov-action@v3.1.4\n with:\n file: pyright_report/cobertura.xml\n flags: pyright39\n env_vars: PYTHON_VERSION\n name: codecov-umbrella\n fail_ci_if_error: false\n\n\n\n min-version-policy:\n name: Minimum Version Policy\n runs-on: \"ubuntu-latest\"\n needs: detect-ci-trigger\n if: needs.detect-ci-trigger.outputs.triggered == 'false'\n defaults:\n run:\n shell: bash -l {0}\n\n strategy:\n matrix:\n environment-file: [\"bare-minimum\", \"min-all-deps\"]\n fail-fast: false\n\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 0 # Fetch all history for all branches and tags.\n\n - name: Setup micromamba\n uses: mamba-org/setup-micromamba@v1\n with:\n environment-name: xarray-tests\n create-args: >-\n python=3.11\n pyyaml\n conda\n python-dateutil\n\n - name: minimum versions policy\n run: |\n python ci/min_deps_check.py ci/requirements/${{ matrix.environment-file }}.yml\n", "logs": "xarray/core/combine.py .. [ 42%]\nxarray/core/common.py ........... [ 45%]\nxarray/core/computation.py ...... [ 47%]\nxarray/core/concat.py . [ 48%]\nxarray/core/coordinates.py .. [ 48%]\nxarray/core/dataarray.py .........F..................................... [ 64%]\n........ [ 67%]\nxarray/core/dataset.py ............................................ [ 82%]\nxarray/core/extensions.py . [ 82%]\nxarray/core/groupby.py . [ 82%]\nxarray/core/indexing.py ... [ 83%]\nxarray/core/merge.py . [ 84%]\nxarray/core/options.py . [ 84%]\nxarray/core/parallel.py . [ 84%]\nxarray/core/rolling.py .... [ 86%]\nxarray/core/rolling_exp.py ...... [ 88%]\nxarray/core/utils.py . [ 88%]\nxarray/core/variable.py ... [ 89%]\nxarray/namedarray/_aggregations.py ............. [ 93%]\nxarray/namedarray/_array_api.py .... [ 95%]\nxarray/namedarray/core.py . [ 95%]\nxarray/plot/dataarray_plot.py . [ 95%]\nxarray/plot/facetgrid.py .. [ 96%]\nxarray/plot/utils.py .......... [100%]\n\n=================================== FAILURES ===================================\n______________ [doctest] xarray.core.dataarray.DataArray.curvefit ______________\n6318 0.04744543, 0.03602333, 0.03129354, 0.01074885, 0.01284436,\n6319 0.00910995]])\n6320 Coordinates:\n6321 * x (x) int64 0 1 2\n6322 * time (time) int64 0 1 2 3 4 5 6 7 8 9 10\n6323 \n6324 Fit the exponential decay function to the data along the ``time`` dimension:\n6325 \n6326 >>> fit_result = da.curvefit(\"time\", exp_decay)\n6327 >>> fit_result[\"curvefit_coefficients\"].sel(\nDifferences (unified diff with -expected +actual):\n @@ -1,4 +1,4 @@\n \n -array([1.05692035, 1.73549638, 2.9421577 ])\n +array([1.05692036, 1.73549638, 2.94215771])\n Coordinates:\n * x (x) int64 0 1 2\n\n/home/runner/work/xarray/xarray/xarray/core/dataarray.py:6327: DocTestFailure\n=========================== short test summary info ============================\nFAILED xarray/core/dataarray.py::xarray.core.dataarray.DataArray.curvefit\n=================== 1 failed, 297 passed in 64.59s (0:01:04) ===================\n##[error]Process completed with exit code 1.\n", "diff": "diff --git a/doc/api.rst b/doc/api.rst\nindex 24c3aee7..38844f22 100644\n--- a/doc/api.rst\n+++ b/doc/api.rst\n@@ -182,6 +182,7 @@ Computation\n Dataset.groupby_bins\n Dataset.rolling\n Dataset.rolling_exp\n+ Dataset.cumulative\n Dataset.weighted\n Dataset.coarsen\n Dataset.resample\n@@ -378,6 +379,7 @@ Computation\n DataArray.groupby_bins\n DataArray.rolling\n DataArray.rolling_exp\n+ DataArray.cumulative\n DataArray.weighted\n DataArray.coarsen\n DataArray.resample\ndiff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py\nindex 4533ea7d..7db2eeaa 100644\n--- a/xarray/core/dataarray.py\n+++ b/xarray/core/dataarray.py\n@@ -6328,7 +6328,7 @@ class DataArray(\n ... param=\"time_constant\"\n ... ) # doctest: +NUMBER\n \n- array([1.05692035, 1.73549638, 2.9421577 ])\n+ array([1.0569203, 1.7354963, 2.9421577])\n Coordinates:\n * x (x) int64 0 1 2\n param DataArrayRolling:\n+ \"\"\"\n+ Rolling window object for DataArrays.\n+\n+ Parameters\n+ ----------\n+ dims : iterable of hashable\n+ The name(s) of the dimensions to create the cumulative window along\n+ min_periods : int or None, default: None\n+ Minimum number of observations in window required to have a value\n+ (otherwise result is NA). The default is 1 (note this is different\n+ from ``Rolling``, whose default is the size of the window).\n+\n+ Returns\n+ -------\n+ core.rolling.DataArrayRolling\n+\n+ Examples\n+ --------\n+ Create rolling seasonal average of monthly data e.g. DJF, JFM, ..., SON:\n+\n+ >>> da = xr.DataArray(\n+ ... np.linspace(0, 11, num=12),\n+ ... coords=[\n+ ... pd.date_range(\n+ ... \"1999-12-15\",\n+ ... periods=12,\n+ ... freq=pd.DateOffset(months=1),\n+ ... )\n+ ... ],\n+ ... dims=\"time\",\n+ ... )\n+\n+ >>> da\n+ \n+ array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.])\n+ Coordinates:\n+ * time (time) datetime64[ns] 1999-12-15 2000-01-15 ... 2000-11-15\n+\n+ >>> da.cumulative(\"time\").sum()\n+ \n+ array([ 0., 1., 3., 6., 10., 15., 21., 28., 36., 45., 55., 66.])\n+ Coordinates:\n+ * time (time) datetime64[ns] 1999-12-15 2000-01-15 ... 2000-11-15\n+\n+ See Also\n+ --------\n+ DataArray.rolling\n+ Dataset.cumulative\n+ core.rolling.DataArrayRolling\n+ \"\"\"\n+ from xarray.core.rolling import DataArrayRolling\n+\n+ # Could we abstract this \"normalize and check 'dim'\" logic? It's currently shared\n+ # with the same method in Dataset.\n+ if isinstance(dim, str):\n+ if dim not in self.dims:\n+ raise ValueError(\n+ f\"Dimension {dim} not found in data dimensions: {self.dims}\"\n+ )\n+ dim = {dim: self.sizes[dim]}\n+ else:\n+ missing_dims = set(dim) - set(self.dims)\n+ if missing_dims:\n+ raise ValueError(\n+ f\"Dimensions {missing_dims} not found in data dimensions: {self.dims}\"\n+ )\n+ dim = {d: self.sizes[d] for d in dim}\n+\n+ return DataArrayRolling(self, dim, min_periods=min_periods or 1, center=False)\n+\n def coarsen(\n self,\n dim: Mapping[Any, int] | None = None,\ndiff --git a/xarray/core/dataset.py b/xarray/core/dataset.py\nindex d010bfba..03269007 100644\n--- a/xarray/core/dataset.py\n+++ b/xarray/core/dataset.py\n@@ -10272,14 +10272,60 @@ class Dataset(\n \n See Also\n --------\n- core.rolling.DatasetRolling\n+ Dataset.cumulative\n DataArray.rolling\n+ core.rolling.DatasetRolling\n \"\"\"\n from xarray.core.rolling import DatasetRolling\n \n dim = either_dict_or_kwargs(dim, window_kwargs, \"rolling\")\n return DatasetRolling(self, dim, min_periods=min_periods, center=center)\n \n+ def cumulative(\n+ self,\n+ dim: str | Iterable[Hashable],\n+ min_periods: int | None = 1,\n+ ) -> DatasetRolling:\n+ \"\"\"\n+ Rolling window object for Datasets\n+\n+ Parameters\n+ ----------\n+ dims : iterable of hashable\n+ The name(s) of the dimensions to create the cumulative window along\n+ min_periods : int or None, default: None\n+ Minimum number of observations in window required to have a value\n+ (otherwise result is NA). The default is 1 (note this is different\n+ from ``Rolling``, whose default is the size of the window).\n+\n+ Returns\n+ -------\n+ core.rolling.DatasetRolling\n+\n+ See Also\n+ --------\n+ Dataset.rolling\n+ DataArray.cumulative\n+ core.rolling.DatasetRolling\n+ \"\"\"\n+ from xarray.core.rolling import DatasetRolling\n+\n+ if isinstance(dim, str):\n+ if dim not in self.dims:\n+ raise ValueError(\n+ f\"Dimension {dim} not found in data dimensions: {self.dims}\"\n+ )\n+ dim = {dim: self.sizes[dim]}\n+ else:\n+ missing_dims = set(dim) - set(self.dims)\n+ if missing_dims:\n+ raise ValueError(\n+ f\"Dimensions {missing_dims} not found in data dimensions: {self.dims}\"\n+ )\n+ dim = {d: self.sizes[d] for d in dim}\n+\n+ return DatasetRolling(self, dim, min_periods=min_periods or 1, center=False)\n+\n def coarsen(\n self,\n dim: Mapping[Any, int] | None = None,\ndiff --git a/xarray/tests/test_rolling.py b/xarray/tests/test_rolling.py\nindex cb7b723a..d019e52d 100644\n--- a/xarray/tests/test_rolling.py\n+++ b/xarray/tests/test_rolling.py\n@@ -461,6 +461,24 @@ class TestDataArrayRollingExp:\n ):\n da.rolling_exp(time=10, keep_attrs=True)\n \n+ @pytest.mark.parametrize(\"func\", [\"mean\", \"sum\"])\n+ @pytest.mark.parametrize(\"min_periods\", [None, 1, 20])\n+ def test_cumulative(self, da, func, min_periods) -> None:\n+ # One dim\n+ result = getattr(da.cumulative(\"time\", min_periods=min_periods), func)()\n+ expected = getattr(\n+ da.rolling(time=da.time.size, min_periods=min_periods or 1), func\n+ )()\n+ assert_identical(result, expected)\n+\n+ # Multiple dim\n+ result = getattr(da.cumulative([\"time\", \"a\"], min_periods=min_periods), func)()\n+ expected = getattr(\n+ da.rolling(time=da.time.size, a=da.a.size, min_periods=min_periods or 1),\n+ func,\n+ )()\n+ assert_identical(result, expected)\n+\n \n class TestDatasetRolling:\n @pytest.mark.parametrize(\n@@ -785,6 +803,25 @@ class TestDatasetRolling:\n expected = getattr(getattr(ds.rolling(time=4), name)().rolling(x=3), name)()\n assert_allclose(actual, expected)\n \n+ @pytest.mark.parametrize(\"func\", [\"mean\", \"sum\"])\n+ @pytest.mark.parametrize(\"ds\", (2,), indirect=True)\n+ @pytest.mark.parametrize(\"min_periods\", [None, 1, 20])\n+ def test_cumulative(self, ds, func, min_periods) -> None:\n+ # One dim\n+ result = getattr(ds.cumulative(\"time\", min_periods=min_periods), func)()\n+ expected = getattr(\n+ ds.rolling(time=ds.time.size, min_periods=min_periods or 1), func\n+ )()\n+ assert_identical(result, expected)\n+\n+ # Multiple dim\n+ result = getattr(ds.cumulative([\"time\", \"x\"], min_periods=min_periods), func)()\n+ expected = getattr(\n+ ds.rolling(time=ds.time.size, x=ds.x.size, min_periods=min_periods or 1),\n+ func,\n+ )()\n+ assert_identical(result, expected)\n+\n \n @requires_numbagg\n class TestDatasetRollingExp:\n"}