Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_attr bug #404

Closed
1 task done
juliettelavoie opened this issue May 15, 2024 · 0 comments · Fixed by #405
Closed
1 task done

update_attr bug #404

juliettelavoie opened this issue May 15, 2024 · 0 comments · Fixed by #405
Labels
bug Something isn't working

Comments

@juliettelavoie
Copy link
Contributor

juliettelavoie commented May 15, 2024

Setup Information

  • xscen version: 0.9
  • Python version: 3.11
  • Operating System: linux
    env xscen-0.9

Description

compute_delta casse sur update_attr

  File "/home/jlavoie/Projets/xscen/xscen/config.py", line 224, in _wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/jlavoie/Projets/xscen/xscen/aggregate.py", line 646, in compute_deltas
    update_attr(
  File "/home/jlavoie/Projets/xscen/xscen/utils.py", line 145, in update_attr
    f"attr{i}": dso.attrs.get(key, dso.attrs.get(attr, "")).strip(" .")
                ^^^^^^^^^
AttributeError: 'str' object has no attribute 'attrs'

Steps To Reproduce

ds= xr.open_zarr('/PATH/xscen-template/test1/climatology/CMIP6_ScenarioMIP_CMCC_CMCC-ESM2_ssp245_r1i1p1f1_global_MS_climatology.zarr')
xs.compute_deltas(ds, reference_horizon='1951-1980')

Additional context

Je pense que associer un dict à une liste dans laquelle on est en train d'iterate, ça bug.

        others = {
            f"attr{i}": dso.attrs.get(attr, "").strip(" .")
            for i, dso in enumerate(others, 1)
        }

Contribution

  • I would be willing/able to open a Pull Request to address this bug.
@juliettelavoie juliettelavoie added the bug Something isn't working label May 15, 2024
juliettelavoie added a commit that referenced this issue May 15, 2024
<!-- Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [x] This PR addresses an already opened issue (for bug fixes /
features)
    - This PR fixes #404 
- [ ] (If applicable) Documentation has been added / updated (for bug
fixes / features).
- [ ] (If applicable) Tests have been added.
- [x] This PR does not seem to break the templates.
- [x] CHANGES.rst has been updated (with summary of main changes).
- [x] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added.

### What kind of change does this PR introduce?

* A few fixes to the templates due to changes in xscen and xarray
* Fix #404, I don't know why this worked in the past but not now. From
my understanding there were 2 problems:
1) We iterate over `others` and assign it to `others`. This breaks the
iteration.
2) In the first instance, we pass a dict of dataset to create a dict of
str (l.137). Then, when we iterate over `others` in l.147, it is no
longuer a dict of dataset, we can't get to `attrs`.
Let me know if I misunderstood something.

### Does this PR introduce a breaking change?
i don't think so.

### Other information:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant