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

xugrid.open_dataset results in a locked netCDF file #309

Open
Huite opened this issue Jan 23, 2025 · 0 comments
Open

xugrid.open_dataset results in a locked netCDF file #309

Huite opened this issue Jan 23, 2025 · 0 comments

Comments

@Huite
Copy link
Collaborator

Huite commented Jan 23, 2025

Current implementation does this:

def open_dataset(*args, **kwargs):
    ds = xr.open_dataset(*args, **kwargs)
    return UgridDataset(ds) 

Internally, the UgridDataset constructor creates a new dataset, and so the ds reference is lost, making UgridDataset.close() a dud.

We should likely do something like:

class UgridDataset:
    def __init__(self, dataset):
        self._original = dataset
        # ... rest of initialization
    
    def close(self):
        self._original.close()

It might be possible that dataset is None, though.

Explicit indexes would also solve this, since we'd just use/return an ordinary xarray dataset.

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