Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Keep attrs in map_over_subtree #279

Merged
merged 3 commits into from
Nov 27, 2023

Conversation

slevang
Copy link
Contributor

@slevang slevang commented Nov 20, 2023

Comment on lines 214 to 217
if node_of_first_tree.has_data
else node_of_first_tree.ds
if node_of_first_tree.has_attrs
else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not even know that this double if else was valid python!

Could we perhaps rewrite this to be more intuitive, e.g.

if node.has_data:
    result = func_with_error_context(...)
elif node.has_attrs:
    # propagate attrs
    result = node.ds
else:
    # nothing to propagate so use fastpath to create empty node in new tree
    result = None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, neither did I. For some reason when I first looked at these lines I thought it was a list comprehension and had to have google remind me whether you can elif in a comprehension (you can not, but you can do this weird syntax 🤷 ). Fixed.

@TomNicholas
Copy link
Member

Thanks for the bug report and the fix @slevang !

@slevang slevang requested a review from TomNicholas November 26, 2023 20:37
@TomNicholas TomNicholas enabled auto-merge (squash) November 27, 2023 01:31
@TomNicholas TomNicholas disabled auto-merge November 27, 2023 16:47
@TomNicholas TomNicholas merged commit 66397e8 into xarray-contrib:main Nov 27, 2023
13 of 14 checks passed
@TomNicholas TomNicholas mentioned this pull request Nov 27, 2023
flamingbear pushed a commit to flamingbear/rewritten-datatree that referenced this pull request Jan 19, 2024
* keep attrs in map_over_subtree

* more intelligible logic

---------

Co-authored-by: Tom Nicholas <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attributes get dropped on empty parent nodes
2 participants