pydata / pydata/xarray

bug or unclear definition of combine_attrs with xr.merge()

Open
#5,436 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

topic-metadata
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Hi all,
I use the latest version of xarray (0.18) and I have some problems. Here are very simple examples:

velocity = xr.DataArray(7.3, name='velocity', attrs={'units':'m/s'})
elevation = xr.DataArray(3.5, name='elevation', attrs={'units':'m'})
  1. When using ds =xr.merge([velocity, elevation], combine_attrs='drop') I expect ds not have any attrs but I may expect variables velocity and elevation to keep their own attributes. This is not the case. All variables loose their attributes

  2. When using combine_attrs='drop_conflicts', elevation and velocity keeps their own units and ds has no attrs.

  3. Then, if we set elevation units to be the same as velocity units and use combine_attrs='drop_conflicts', then ds get a new attibute wich is this common units

As a conclucion, the combine_attrs flag definition is really not clear because it seems to control the final merged dataset attrs but, in reality, can also affects merged variables attributes. From my point of view, behaviour of combine_attrs is not consistent depending on the chosen option.

I would expect merged variables to be (as much as possible) untouched when merged and the combine_attrs to only control the attributes of the merged dataset.

Thanks

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 by reproducing the two xr.merge() examples using combine_attrs='drop' and 'drop_conflicts' with the velocity and elevation DataArrays shown in the issue. Read the merge behavior around dataset and variable attributes, then check existing tests for combine_attrs. Done means the intended attribute semantics are established and covered by an appropriate regression test or clarified documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.