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

__getitem__ on search results operates on root not result #1877

Open
braingram opened this issue Dec 17, 2024 · 0 comments
Open

__getitem__ on search results operates on root not result #1877

braingram opened this issue Dec 17, 2024 · 0 comments

Comments

@braingram
Copy link
Contributor

Description of the problem

I expected providing a key/index to a search result would descend relative to the search result. However it's unclear what it's doing (see the example below).

The documentation doesn't make it clear what "descending" into a search result means:
https://asdf.readthedocs.io/en/latest/asdf/features.html#descending-into-child-nodes

Example of the problem

>>> import asdf
>>> af = asdf.AsdfFile({"a": 1, "b": {"c": [1, 2, 3]}})
>>> af.search("c")
root (AsdfObject)
└─b (dict)
  └─c (list): [1, 2, 3]
>>> af.search("c")[0]   # I expected this to return 1 since it's the 0th item in "c"
KeyError: 0
>>> af.search()["a"]   # roughly matches the example, suggesting indexing is relative to the root
a (int): 1
>>> af.search("c")["a"]  # maybe this makes sense since there's no "c" in "a"
No results found.
>>> af.search("c")["b"]  # maybe this should return "c"?
No results found.

System information

asdf version: main
python version: 3.10
operating system: mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant