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

Out of node access to variables in .ds #102

Closed
wants to merge 32 commits into from

Conversation

TomNicholas
Copy link
Member

@TomNicholas TomNicholas commented May 28, 2022

Intended to close part (2) of #80, but currently raises a RecursionError.

Allow path-like access to DataArray objects stored in other nodes via getitem

Comment on lines 483 to 500
def test_getitem(self):
dt = create_test_datatree()
da = dt.ds["a"]
print(da)
expected = xr.DataArray(dims=("y",), data=[6, 7, 8])
print(expected)
xrt.assert_equal(da, expected)

# @pytest.mark.xfail
def test_get_items_in_other_nodes(self):
...
dt = create_test_datatree()
node_dsv = dt["set1"].ds

xrt.assert_identical(node_dsv["../a"], dt["a"])

# don't allow retrieving other DataTree nodes
with pytest.raises(KeyError):
node_dsv["../set2"]
Copy link
Member Author

@TomNicholas TomNicholas May 28, 2022

Choose a reason for hiding this comment

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

Calling .ds.__getitem__ anywhere in these tests currently raises a RecursionError, and the cause is something complicated to do with xarray.Dataset's __getattr__ manipulation interacting with me adding a new _wrapping_node attribute to my DatasetView subclass.

dt = create_test_datatree()
node_dsv = dt["set1"].ds

xrt.assert_identical(node_dsv["../a"], dt["a"])
Copy link
Member

Choose a reason for hiding this comment

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

Related to #99 (comment)
When users pull out a dataset from a datatree, how do they know that it has access to "../a". Is it shown in the representation and/or are you planning to change the __repr__ of Dataset?

cc: @aurghs

Copy link
Member Author

Choose a reason for hiding this comment

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

I honestly hadn't really thought of that - with this implementation they wouldn't know without looking at documentation, which is not ideal.

@TomNicholas TomNicholas marked this pull request as draft June 16, 2022 15:08
@TomNicholas
Copy link
Member Author

Based on discussion in #99 (comment) we will leave this for now, and see if it's actually something that users particularly want later.

@TomNicholas TomNicholas added the enhancement New feature or request label Jun 17, 2022
@TomNicholas TomNicholas changed the base branch from datasetview2 to main June 26, 2022 12:36
@TomNicholas
Copy link
Member Author

Closing this as probably not a good idea.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposed API and design for .ds data access
2 participants