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

Scene.__getitem__ not "greedy" enough #2331

Open
BENR0 opened this issue Dec 20, 2022 · 0 comments
Open

Scene.__getitem__ not "greedy" enough #2331

BENR0 opened this issue Dec 20, 2022 · 0 comments
Labels
Milestone

Comments

@BENR0
Copy link
Collaborator

BENR0 commented Dec 20, 2022

Describe the bug
Currently it is possible to get a dataset identified only by name with a more concise DataID with name and for example resolution. This is also relevant for DataID in Scene testing and dataset deletion (see code examples below).
A __setitem__ operation with a more specific DataID does not overwrite the dataset with a less specific DataID which is good but the DataID added to the dependency_tree is wrong.

To Reproduce

from satpy.tests.utils import make_dataid
scene = Scene()
scene['1'] = ds1 = xr.DataArray(np.arange(5))
dataid = make_dataid(name='1', resolution=2000) 
print(dataid in scene) # => True should be False

scene[dataid] # => returns ds1 but should return KeyError

del scene[dataid]
print(scene) # => should not be empty


scene['1'] = ds1 = xr.DataArray(np.arange(5))
print(scene._dependency_tree)

scene[dataid] = ds2 = xr.DataArray(np.arange(5, 10))
print(scene._dependency_tree)

Expected behavior
See code example.

Environment Info:

  • OS: Linux
  • Satpy Version: main branch
  • PyResample Version: 1.26.0

Additional context
As far as I can see this behaviour is due to the get_key method in DatasetDict (

def get_key(self, match_key, num_results=1, best=True, **dfilter):
) not being "greedy" enough.

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

No branches or pull requests

1 participant