Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read some unstructured datasets (UnboundLocalError) #315

Open
sadielbartholomew opened this issue Jan 13, 2025 · 0 comments · May be fixed by #316
Open

Unable to read some unstructured datasets (UnboundLocalError) #315

sadielbartholomew opened this issue Jan 13, 2025 · 0 comments · May be fixed by #316
Assignees
Labels
bug Something isn't working

Comments

@sadielbartholomew
Copy link
Member

For example, using the cfplot_data example LFric dataset as used by the cf-plot documentation, lfric_initial.nc, we hit an UnboundLocalError due to bad logic to process a defined variable mesh so that it can be undefined when we attempt to report an attribute on it in a log call:

>>> f = cfdm.read("/home/slb93/git-repos/cf-plot/cfplot/test/cfplot_data/lfric_initial.nc")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slb93/git-repos/cfdm/cfdm/read_write/read.py", line 416, in read
    fields = netcdf.read(
             ^^^^^^^^^^^^
  File "/home/slb93/git-repos/cfdm/cfdm/decorators.py", line 171, in verbose_override_wrapper
    return method_with_verbose_kwarg(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/slb93/git-repos/cfdm/cfdm/read_write/netcdf/netcdfread.py", line 1827, in read
    field_or_domain = self._create_field_or_domain(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/slb93/git-repos/cfdm/cfdm/read_write/netcdf/netcdfread.py", line 3788, in _create_field_or_domain
    print(mesh.mesh_ncvar)
          ^^^^
UnboundLocalError: cannot access local variable 'mesh' where it is not associated with a value

This pervades downstream in cf-python, so cf.read will also hit the error.

PR to follow.

Env

Using the up-to-date present main branches for cfdm (and cf-python when tested downstream):

>>> cfdm.environment()
Platform: Linux-6.6.65-1-MANJARO-x86_64-with-glibc2.40 
Python: 3.12.0 /home/slb93/miniconda3/envs/cf-env-312/bin/python
packaging: 24.1 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/packaging/__init__.py
numpy: 1.26.4 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/numpy/__init__.py
cfdm.core: 1.11.2.0 /home/slb93/git-repos/cfdm/cfdm/core/__init__.py
HDF5 library: 1.14.2 
netcdf library: 4.9.2 
netCDF4: 1.6.5 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/netCDF4/__init__.py
h5netcdf: 1.3.0 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/h5netcdf/__init__.py
h5py: 3.11.0 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/h5py/__init__.py
s3fs: 2024.6.1 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/s3fs/__init__.py
scipy: 1.14.0 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/scipy/__init__.py
dask: 2024.7.1 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/dask/__init__.py
cftime: 1.6.2 /home/slb93/miniconda3/envs/cf-env-312/lib/python3.12/site-packages/cftime/__init__.py
cfdm: 1.11.2.0 /home/slb93/git-repos/cfdm/cfdm/__init__.py
@sadielbartholomew sadielbartholomew added the bug Something isn't working label Jan 13, 2025
@sadielbartholomew sadielbartholomew self-assigned this Jan 13, 2025
@sadielbartholomew sadielbartholomew changed the title Bug: unable to read some unstructured datasets due to UnboundLocalError Bug: unable to read some unstructured datasets (UnboundLocalError) Jan 13, 2025
@sadielbartholomew sadielbartholomew changed the title Bug: unable to read some unstructured datasets (UnboundLocalError) Unable to read some unstructured datasets (UnboundLocalError) Jan 13, 2025
sadielbartholomew added a commit to sadielbartholomew/cfdm that referenced this issue Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant