home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 491866549

This data as json

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/2954#issuecomment-491866549 https://api.github.com/repos/pydata/xarray/issues/2954 491866549 MDEyOklzc3VlQ29tbWVudDQ5MTg2NjU0OQ== 500246 2019-05-13T15:18:33Z 2019-05-13T15:18:33Z CONTRIBUTOR

In our code, this problem gets triggered because of xarrays lazy handling. If we have

with xr.open_dataset('file.nc') as ds: val = ds["field"] return val

then when a caller tries to use val, xarray reopens the dataset and does not close it again. This means the context manager is actually useless: we're using the context manager to close the file as soon as we have accessed the value, but later the file gets opened again anyway. This is against the intention of the code.

We can avoid this by calling val.load() from within the context manager, as the linked satpy PR above does. But what is the intention of xarrays design here? Should lazy reading close the file after opening and reading the value? I would say it probably should do something like

if file_was_not_open: open file get value close file # this step currently omitted return value else: get value return value

is not closing the file after it has been opened for retrieving a "lazy" file by design, or might this be considered a wart/bug?

{
    "total_count": 2,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 2
}
  442617907
Powered by Datasette · Queries took 1.13ms · About: xarray-datasette