pydata / pydata/xarray

A means of viewing all differences between two datatrees

Open
#9,929 11 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is your feature request related to a problem?

It can be frustrating to figure out why two Datatrees are not returning True when running xarray.DataTree.identical() or xarray.DataTree.equals().

Currently, if xarray's diff functions detect any difference in the tree structure, they raise at that point, and so do not show all of the differences. Thus, the current functions excel when the user wants to check that two datatrees are equal, but not when the user wants to discover subtle differences — and there are cases in which such subtle differences may be desired.

For example, when developing or testing new datatree transformations, I would like to be able to quickly check that the datatree has been modified as expected. Or, when expecting two datasets to be the same but they are not, it would be helpful to be able to quickly traverse the entire tree structure and see the differences.

Describe the solution you'd like

I think it would be useful to have a means of visually representing all the differences between two xarray Datatree objects, either showing the whole trees and highlighting all the differences, or showing only the differences.

I'm imagining a solution that shows a comparison report similar to ncompare, which provides aligned and colorized difference reports for quick assessments of groups, variable names, types, shapes, and attributes (see ncompare's readme gif or the example notebook). In contrast to ncompare, the proposed solution would work on the xarray data model.

The solution could be a new function, perhaps in the testing suite, such as xarray.testing.all_differences(dt1: DataTree, dt2: DataTree). This could be based on the diff_datatree_repr function that is used in assert_isomorphic: https://github.com/pydata/xarray/blob/1486beaf8f4b4d5e30779d19425843212deea5ad/xarray/testing/assertions.py#L81
https://github.com/pydata/xarray/blob/1486beaf8f4b4d5e30779d19425843212deea5ad/xarray/core/formatting.py#L1053

Describe alternatives you've considered

Showing differences between Datatrees will achieve similar goals to https://github.com/nasa/ncompare. However, a solution in xarray would be different than ncompare, because ncompare looks directly at the netCDF/HDF files, and makes assumptions that that is the data model you care about. xarray instead opens netCDF (or a range of other formats) into an in-memory object which has a data model that is almost but not quite the same as netCDF's data model, then xarray's assertions compare those. For example, netCDF can have dimensions with no corresponding coordinate values, which aren't a part of xarray's data model. In addition, a solution in xarray would be applicable to data coming from additional formats like Zarr.

Additional context

No response

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/testing/assertions.py, especially diff_datatree_repr and assert_isomorphic, then inspect xarray/core/formatting.py around the referenced formatting function. Review the issue discussion and existing tests before settling the comparison-report design. Done means a documented way to report all relevant differences between two DataTree objects, with coverage for the intended comparisons.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.