• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ouranosinc / xclim / 8251089024 / 1
92%
main: 92%

Build:
DEFAULT BRANCH: main
Ran 12 Mar 2024 03:12PM UTC
Files 70
Run time 5s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

12 Mar 2024 03:01PM UTC coverage: 90.196%. Remained the same
8251089024.1

push

github

web-flow
Fix map_blocks for DataArray with cftime and sdba_encode_cf (#1674)

### What kind of change does this PR introduced
**tl;dr  : me fix issue.**

I think this issue stems from a change in recent xarray, but the case
was untested by xclim. The solution was to iterate over a list that is
"disconnected" from the dictionary.

The issue occurs when a _DataArray_ that has a coordinate made of
`cftime` objects is passed to a `map_blocks`-wrapped function and
xclim's global option `sdba_encode_cf` is True.

The previous encoding code was iterating over the coordinates with
`coords.items()`. When it would modify a the cftime coord, this would
fail as you can't modify a dictionary while it is being iterated upon.

Only happens if the option to encode is activated, only happens if there
is a cftime coord and only happens on `DataArray` objects. I'm not 100%
sure why, but I think `Dataset.coords.items` does not map directly to a
dict. We usually use `Dataset` objects in function wrapped by
`map_blocks` (or `map_groups`). The culprit here was the polynomial's
trend computation which uses a `DataArray`.

### Reason for the apparent dask-dependency
The interesting part is that this bug does not depend on the fact that
the data is using dask or not. But it led me to discover another "issue"
or, rather, "edgecase" .

In `xscen.adjust` we wrap the xclim call with options:
```python3
        with xc.set_options(sdba_encode_cf=True, sdba_extra_output=False):
            out = ADJ.adjust(sim_sel, **xclim_adjust_args)
```
Here, for DQM, the `adjust` method is wrapped by `map_blocks`. When
`sim_sel` uses dask, the actual adjustment is, of course, not executed
here. Only when the computation is triggered will the adjustment
function be run, and only then will it call the polynomial detrending.
But at that moment, the `sdba_encode_cf` option is not set anymore! So
the issue was not raised for the "dask" case.

When `sim_sel` was not using... (continued)

8648 of 9588 relevant lines covered (90.2%)

5.18 hits per line

Source Files on job run-{{ matrix.tox-env }}-{{ matrix.os }} - 8251089024.1
  • Tree
  • List 0
  • Changed 2
  • Source Changed 0
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 8251089024
  • bea276a0 on github
  • Prev Job for on main (#8250294806.1)
  • Next Job for on main (#8297492467.1)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc