home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 1033950863

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1033950863 I_kwDOAMm_X849oNaP 5888 open_[mf]dataset ds.encoding['source'] for pathlib.Path? 12465248 closed 0     2 2021-10-22T21:10:23Z 2022-09-21T17:11:58Z 2022-09-13T07:17:39Z CONTRIBUTOR      

The question: do you want to support pathlib objects arriving at ds.encoding['source']?

What happened: If you pass a pathlib object to open_[mf]dataset, the ds.encoding['source'] is not set.

What you expected to happen: I believe that Paths used to work and now they dont, which greatly confused me.

Minimal Complete Verifiable Example:

```python (hv) jamesmcc@panama[523]:~> cat enc_source_pathlib.py import numpy as np from pathlib import Path import xarray as xr

inspiration in the test

https://github.com/pydata/xarray/blob/97887fd9bbfb2be58b491155c6bb08498ce294ca/xarray/tests/test_backends.py#L4918

rnddata = np.random.randn(10) ds = xr.Dataset({"foo": ("x", rnddata)}) file_name = "rnddata.nc" ds.to_netcdf(file_name)

with xr.open_dataset(file_name) as ds: assert ds.encoding["source"] == file_name

with xr.open_dataset(Path(file_name)) as ds: print(ds.encoding) assert ds.encoding["source"] == file_name

(hv) jamesmcc@panama[524]:~/> ipython enc_source_pathlib.py /Users/jamesmcc/python_libs/xarray/xarray/backends/cfgrib_.py:28: UserWarning: Failed to load cfgrib - most likely there is a problem accessing the ecCodes library. Try import cfgrib to get the full error message "Failed to load cfgrib - most likely there is a problem accessing the ecCodes library. " /Users/jamesmcc/python_libs/xarray/xarray/backends/plugins.py:61: RuntimeWarning: Engine 'cfgrib' loading failed: Cannot find the ecCodes library warnings.warn(f"Engine {name!r} loading failed:\n{ex}", RuntimeWarning) {'unlimited_dims': set()}


KeyError Traceback (most recent call last) ~/python_libs/xarray/enc_source_pathlib.py in <module> 16 with xr.open_dataset(Path(file_name)) as ds: 17 print(ds.encoding) ---> 18 assert ds.encoding["source"] == file_name 19 20

KeyError: 'source' ```

I scanned git blame, but didnt turn up any obviously undesired changes.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5888/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 0.734ms · About: xarray-datasette