File lock not being released using rasterio engine
What happened?
Open an ASCII raster file with xarray and rioxarray rasterio extension and then try to delete the ASCII file, get PermissionError:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process
Doing the same with the direct rioxarray.open_rasterio() method works fine - the file can be deleted.
What did you expect to happen?
Expect that the file lock is released upon the context manager closing so that I can delete the input file.
Minimal Complete Verifiable Example
# This doesn't work:
with xarray.open_dataset(ascii_file, engine="rasterio") as ds:
ds = ds.load()
ascii_file.unlink()
> PermissionError: [WinError 32] The process cannot access the file because it is being used by another process
# This works as expected:
with rioxarray.open_rasterio(ascii_file) as ds:
ds = ds.load()
ascii_file.unlink()
MVCE confirmation
- [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- [X] Complete example — the example is self-contained, including all data and the text of any traceback.
- [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- [x] New issue — a search of GitHub Issues suggests this is not a duplicate.
Relevant log output
No response
Anything else we need to know?
No response
Environment
xarray: 2022.6.0 pandas: 1.5.0 numpy: 1.23.3 scipy: 1.9.1 netCDF4: 1.6.1 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.3.2 cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: None cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 65.3.0 pip: 22.2.2 conda: None pytest: 7.1.3 IPython: None sphinx: None rioxarray: 0.12.2