Skip to content

Handling a PosixPath in preprocess #3001

@lewisjared

Description

@lewisjared

Describe the bug
The REF cloud-scatterplots-cli-ta diagnostic is failing with a recent update to the ESMValCore version on the climate-ref main branch. I think this is a ESMValCore issue rather than config, but happy to be corrected.

@bouweandela

To reproduce:
uv run ref test-cases run --fetch --provider esmvaltool --diagnostic cloud-scatterplots-cli-ta --test-case cmip6

I think the problem line is:

if isinstance(item, (PreprocessorFile, Cube, DataElement)):

If one of the preprocess functions returns a Path then it isn't handled. Not sure if that is an issue with the preprocessors or the the append/extend logic.

Stacktrace below and debug log attached:

  File "/Users/jared/code/climate-ref/software/conda/esmvaltool-efbbc9d45c9eb22679208cc3eac458e67ddb7308/lib/python3.13/site-packages/esmvalcore/_task.py", line 1005, in _run_task
    output_files = task.run()
    ^^^^^^^^^^^^^^^
  File "/Users/jared/code/climate-ref/software/conda/esmvaltool-efbbc9d45c9eb22679208cc3eac458e67ddb7308/lib/python3.13/site-packages/esmvalcore/_task.py", line 301, in run
    self.output_files = self._run(input_files)
    ^^^^^^^^^^^
  File "/Users/jared/code/climate-ref/software/conda/esmvaltool-efbbc9d45c9eb22679208cc3eac458e67ddb7308/lib/python3.13/site-packages/esmvalcore/preprocessor/__init__.py", line 859, in _run
    product.apply(step, self.debug)
    
  File "/Users/jared/code/climate-ref/software/conda/esmvaltool-efbbc9d45c9eb22679208cc3eac458e67ddb7308/lib/python3.13/site-packages/esmvalcore/preprocessor/__init__.py", line 675, in apply
    self.cubes,
  File "/Users/jared/code/climate-ref/software/conda/esmvaltool-efbbc9d45c9eb22679208cc3eac458e67ddb7308/lib/python3.13/site-packages/esmvalcore/preprocessor/__init__.py", line 687, in cubes
    self._cubes = [ds.load() for ds in self.datasets]  # type: ignore
    ^^^^^^^^^^^
  File "/Users/jared/code/climate-ref/software/conda/esmvaltool-efbbc9d45c9eb22679208cc3eac458e67ddb7308/lib/python3.13/site-packages/esmvalcore/dataset.py", line 805, in load
    cube = self._load()
    ^^^^^^^^^^^^^^^
  File "/Users/jared/code/climate-ref/software/conda/esmvaltool-efbbc9d45c9eb22679208cc3eac458e67ddb7308/lib/python3.13/site-packages/esmvalcore/dataset.py", line 887, in _load
    result = preprocess(
    ^^^^^^^^^^^
  File "/Users/jared/code/climate-ref/software/conda/esmvaltool-efbbc9d45c9eb22679208cc3eac458e67ddb7308/lib/python3.13/site-packages/esmvalcore/preprocessor/__init__.py", line 586, in preprocess
    items.extend(item)
    ^^^^^^^^^^^
TypeError: 'PosixPath' object is not iterable
2026-02-24 00:26:55,786 UTC [96280] INFO    esmvalcore._main:805 
If you have a question or need help, please start a new discussion on https://github.com/ESMValGroup/ESMValTool/discussions
If you suspect this is a bug, please open an issue on https://github.com/ESMValGroup/ESMValTool/issues
To make it easier to find out what the problem is, please consider attaching the files run/recipe_*.yml and run/main_log_debug.txt from the output directory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions