error from netCDF in cf.write
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with cfdm/read_write/netcdf/netcdfwrite.py at _write_global_attributes and the netCDF4 Dataset.setncattr call shown in the traceback. Reproduce cf.write in the reported Python environment and identify which global attribute contains the invalid surrogate characters. Done means the affected data can be written without the UnicodeEncodeError and the behavior is covered by an appropriate regression test.
Written by the indexing model from the issue text.
Description
I am processing some CMIP6 data on Jasmin (making time-means). I get the following error. I realise that you probably need more background to diagnose it, but perhaps it's obvious from this much information? As a result of the error, the file is not properly written, just the start of it.
Thanks. Jonathan
Traceback (most recent call last):
File "/home/users/jonathan/bin/grouptime", line 97, in <module>
cf.write(n,ofile)
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.12/mf3-25.3.0-3/envs/jaspy3.12-mf3-25.3.0-3-v20250704/lib/python3.12/site-packages/cfdm/read_write/write.py", line 826, in __new__
netcdf.write(
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.12/mf3-25.3.0-3/envs/jaspy3.12-mf3-25.3.0-3-v20250704/lib/python3.12/site-packages/cfdm/decorators.py", line 171, in verbose_override_wrapper
return method_with_verbose_kwarg(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.12/mf3-25.3.0-3/envs/jaspy3.12-mf3-25.3.0-3-v20250704/lib/python3.12/site-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 5232, in write
self._file_io_iteration(
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.12/mf3-25.3.0-3/envs/jaspy3.12-mf3-25.3.0-3-v20250704/lib/python3.12/site-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 5478, in _file_io_iteration
self._write_global_attributes(fields)
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.12/mf3-25.3.0-3/envs/jaspy3.12-mf3-25.3.0-3-v20250704/lib/python3.12/site-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 4610, in _write_global_attributes
g["netcdf"].setncattr(
File "src/netCDF4/_netCDF4.pyx", line 3087, in netCDF4._netCDF4.Dataset.setncattr
File "src/netCDF4/_netCDF4.pyx", line 1858, in netCDF4._netCDF4._set_att
File "src/netCDF4/_netCDF4.pyx", line 6733, in netCDF4._netCDF4._strencode
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 61-63: surrogates not allowed
- Dominant language
- Python
- Stars
- 151
- Forks
- 23
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NCAS-CMS/cf-python
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Convert to/from iris cubesPossibly taken @davidhassell claimed this 3 days ago. Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Convert from/to `xarray`Possibly taken @davidhassell claimed this 3 days ago. Openenhancement xarray
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
installation
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Attempt at unsupported conservative 3D mesh regriddingMay be free again @sadielbartholomew claimed this 74 days ago, and no pull request is open. Openbug?
All issues in NCAS-CMS/cf-python
Similar issues
-
eegprep-lean: set channel types from the Zarr group's channel_typePossibly taken @claude claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
sccn/eegprep#668 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
blacklanternsecurity/bbot#3679 ·
Maintainers usually reply within 2 days
-
Link Checker ReportOpenBot Type: Bug Type: Documentation
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
speakeasy-api/speakeasy#2159 ·
Maintainers usually reply within 1 day