xarray icon indicating copy to clipboard operation
xarray copied to clipboard

add **encoding** argument in netCDF4 backend

Open wqshen opened this issue 6 months ago • 4 comments

add encoding argument in netCDF4 backend to support reading NetCDF file with non-ASCII path or filename.

The behavior is consistent with upstream netCDF4 library, default path encoding is set to sys.getdefaultfileencoding() .

  • [x] Closes #10357 #8531

wqshen avatar May 29 '25 06:05 wqshen

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. If you have questions, some answers may be found in our contributing guidelines.

welcome[bot] avatar May 29 '25 06:05 welcome[bot]

Nice, can you add a test here please? https://github.com/pydata/xarray/blob/d589df1868b9d6ec197a91da7e3acb8670bb7641/xarray/tests/test_backends.py#L2037

It can simply roundtrip a simple dataset to a file with a filename that doesn't work today.

dcherian avatar May 29 '25 13:05 dcherian

How is this handled in the light of this comment https://github.com/pydata/xarray/issues/9282#issuecomment-2310573129 by @dcherian?

kmuehlbauer avatar May 30 '25 08:05 kmuehlbauer

Hah! Probably good to use filename_encoding since we'll probably to support writing files with such file names.

dcherian avatar May 30 '25 15:05 dcherian