html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/4131#issuecomment-649975829,https://api.github.com/repos/pydata/xarray/issues/4131,649975829,MDEyOklzc3VlQ29tbWVudDY0OTk3NTgyOQ==,5821660,2020-06-26T05:24:15Z,2020-06-26T05:24:15Z,MEMBER,"@rsokl Yes, you're right for your issue. In my comment above I was referring to the case where the file was opened outside xarray.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,634869703 https://github.com/pydata/xarray/issues/4131#issuecomment-649972764,https://api.github.com/repos/pydata/xarray/issues/4131,649972764,MDEyOklzc3VlQ29tbWVudDY0OTk3Mjc2NA==,5821660,2020-06-26T05:15:28Z,2020-06-26T05:15:28Z,MEMBER,"> It isn't obvious to me what the right behavior is here. I can see a case for either closing the file (the user did request it to be closed, after all) or leaving it open. Sure, it's heavily depending on use case. But good to know what and where to look for in case anything unusual is going on.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,634869703 https://github.com/pydata/xarray/issues/4131#issuecomment-641750522,https://api.github.com/repos/pydata/xarray/issues/4131,641750522,MDEyOklzc3VlQ29tbWVudDY0MTc1MDUyMg==,5821660,2020-06-10T06:18:36Z,2020-06-10T06:18:36Z,MEMBER,"This doesn't work when it is opened via netCDF4 and NetCDF4DataStore. ```python import netCDF4 as nc import xarray as xr ncfile = nc.Dataset(""tmp_example.nc"") dstore = xr.backends.NetCDF4DataStore(ncfile) data = xr.open_dataset(dstore) print(ncfile.isopen()) data.close() print(ncfile.isopen()) print(data.foo) ``` ``` True False /home/miniconda/envs/xarray/lib/python3.8/site-packages/xarray/backends/netCDF4_.py in _getitem(self, key) 83 with self.datastore.lock: 84 original_array = self.get_array(needs_lock=False) ---> 85 array = getitem(original_array, key) 86 except IndexError: 87 # Catch IndexError in netCDF4 and return a more informative netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Variable.__getitem__() netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Variable.shape.__get__() netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Variable._getdims() netCDF4/_netCDF4.pyx in netCDF4._netCDF4._ensure_nc_success() RuntimeError: NetCDF: Not a valid ID ``` Also in @rsokl's case the `data._file_obj` is `None` after closing. First I thought that caching might be involved, but it doesn't seem the case. Nevertheless it seems unusual, that opening a file outside xarray will be closed inside xarray. At least I would not expect it, to be closed. Should I open another issue for this, @shoyer? ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,634869703