pydata / pydata/xarray

Test failing test_error_contains_path_of_offending_node

Open
#9,893 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-DataTree topic-error reporting topic-testing
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened?

Trying to package xarray 2024.11.0 in Mageia Caudron, I get this failure when running tests

Python 3.12
Numpy 2.1.0
Pandas 2.2.2

What did you expect to happen?

Test passes

Minimal Complete Verifiable Example

No response

MVCE confirmation
  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
=================================== FAILURES ===================================
________ TestMapOverSubTree.test_error_contains_path_of_offending_node _________

self = <xarray.tests.test_datatree_mapping.TestMapOverSubTree object at 0x7f009b68f8c0>
create_test_datatree = <function create_test_datatree.<locals>._create_test_datatree at 0x7f008eb9dbc0>

    def test_error_contains_path_of_offending_node(self, create_test_datatree):
        dt = create_test_datatree()
        dt["set1"]["bad_var"] = 0
        print(dt)
    
        def fail_on_specific_node(ds):
            if "bad_var" in ds:
                raise ValueError("Failed because 'bar_var' present in dataset")
    
        with pytest.raises(
            ValueError,
            match=re.escape(
                r"Raised whilst mapping function over node with path 'set1'"
            ),
        ):
>           dt.map_over_datasets(fail_on_specific_node)

/builddir/build/BUILD/python-xarray-2024.11.0-build/xarray-2024.11.0/xarray/tests/test_datatree_mapping.py:175: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/builddir/build/BUILD/python-xarray-2024.11.0-build/xarray-2024.11.0/xarray/core/datatree.py:1462: in map_over_datasets
    return map_over_datasets(func, self, *args)
/builddir/build/BUILD/python-xarray-2024.11.0-build/xarray-2024.11.0/xarray/core/datatree_mapping.py:103: in map_over_datasets
    results = func_with_error_context(*node_dataset_args)
/builddir/build/BUILD/python-xarray-2024.11.0-build/xarray-2024.11.0/xarray/core/datatree_mapping.py:133: in wrapper
    return func(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

ds = <xarray.DatasetView> Size: 24B
Dimensions:  ()
Data variables:
    a        int64 8B 0
    b        int64 8B 1
    bad_var  int64 8B 0

    def fail_on_specific_node(ds):
        if "bad_var" in ds:
>           raise ValueError("Failed because 'bar_var' present in dataset")
E           ValueError: Failed because 'bar_var' present in dataset
E           Raised whilst mapping function over node with path 'set1'

/builddir/build/BUILD/python-xarray-2024.11.0-build/xarray-2024.11.0/xarray/tests/test_datatree_mapping.py:167: ValueError

During handling of the above exception, another exception occurred:

self = <xarray.tests.test_datatree_mapping.TestMapOverSubTree object at 0x7f009b68f8c0>
create_test_datatree = <function create_test_datatree.<locals>._create_test_datatree at 0x7f008eb9dbc0>

    def test_error_contains_path_of_offending_node(self, create_test_datatree):
        dt = create_test_datatree()
        dt["set1"]["bad_var"] = 0
        print(dt)
    
        def fail_on_specific_node(ds):
            if "bad_var" in ds:
                raise ValueError("Failed because 'bar_var' present in dataset")
    
>       with pytest.raises(
            ValueError,
            match=re.escape(
                r"Raised whilst mapping function over node with path 'set1'"
            ),
        ):
E       AssertionError: Regex pattern did not match.
E        Regex: "Raised\\ whilst\\ mapping\\ function\\ over\\ node\\ with\\ path\\ 'set1'"
E        Input: "Failed because 'bar_var' present in dataset"

/builddir/build/BUILD/python-xarray-2024.11.0-build/xarray-2024.11.0/xarray/tests/test_datatree_mapping.py:169: AssertionError
----------------------------- Captured stdout call -----------------------------
<xarray.DataTree>
Group: /
│   Dimensions:  (y: 3, x: 2)
│   Dimensions without coordinates: y, x
│   Data variables:
│       a        (y) int64 24B 6 7 8
│       set0     (x) int64 16B 9 10
├── Group: /set1
│   │   Dimensions:  ()
│   │   Data variables:
│   │       a        int64 8B 0
│   │       b        int64 8B 1
│   │       bad_var  int64 8B 0
│   ├── Group: /set1/set1
│   └── Group: /set1/set2
├── Group: /set2
│   │   Dimensions:  (x: 2)
│   │   Dimensions without coordinates: x
│   │   Data variables:
│   │       a        (x) int64 16B 2 3
│   │       b        (x) float64 16B 0.1 0.2
│   └── Group: /set2/set1
└── Group: /set3
Anything else we need to know?

No response

Environment
Python 3.12 Numpy 2.1.0 Pandas 2.2.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with xarray/tests/test_datatree_mapping.py and the failing test_error_contains_path_of_offending_node test, then inspect xarray/core/datatree.py and xarray/core/datatree_mapping.py at the traceback locations. Run the named test and determine why the expected node-path context is absent from the raised error. Done means the test passes while preserving the reported error context.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
data, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.