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

fix overwrite lazy loaded files #242

Open
wants to merge 2 commits into
base: fix/overwrite_lazy_loaded_ds
Choose a base branch
from

Conversation

LuukBlom
Copy link
Collaborator

@LuukBlom LuukBlom commented Jan 31, 2025

Issue addressed

Fixes #

Explanation

Ik zit een beetje te kijken naar die xu_open_dataset PR en ben steeds meer overtuigd dat jullie gewoon load dataset moeten gebruiken.

Is hetzelfde principe als normaal files openen in python:

fd = open(...)
......
fd.close()

of met context managers:

with open(...) as fd:
   ....

Dit is precies wat load_dataset() doet, alleen dan leest die de hele ds uit.
Als je maar een deel wil uitlezen, kan dat nog steeds met:

ds = xr.open_dataset(...)
uds = UGridDataset(ds)
....
ds.close()

of met context manager:

with xr.open_dataset(...) as ds:
  uds = UGridDataset(ds)
  ....

De schuld ligt bij xugrid, want die openen de file en doen er daarna niks meer mee, waardoor het anders is dan wat xarray doet.
Ik heb een testje erbij geschreven in je branch met wat extra uitleg.

Belangrijk te weten dat lazy loading dus eigenlijk alleen mogelijk is in dezelfde scope als waar je de file opent.

Checklist

  • Updated tests or added new tests
  • Branch is up to date with main
  • Updated documentation if needed
  • Updated changelog.rst if needed

Additional Notes (optional)

Add any additional notes or information that may be helpful.

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

Successfully merging this pull request may close these issues.

1 participant