xarray.merge function and major refactor for merge logic#857
xarray.merge function and major refactor for merge logic#857shoyer merged 9 commits intopydata:masterfrom
Conversation
Fixes GH417
New top level :py:func:`merge` function allows for combining variables from
any number of ``Dataset`` and/or ``DataArray`` variables.
Example usage:
>>> arrays = [xr.DataArray(n, name='var%d' % n) for n in range(5)]
>>> xr.merge(arrays)
<xarray.Dataset>
Dimensions: ()
Coordinates:
*empty*
Data variables:
var0 int64 0
var1 int64 1
var2 int64 2
var3 int64 3
var4 int64 4
The internal refactoring also lays the ground work for supporting ufunc-like
functions that merge three or more arguments, such as the full form of
`where`.
| [-1.13563237, 1.21211203, -0.17321465]]) | ||
| second value: <xarray.Variable (x: 2, y: 3)> | ||
| array([[ 1.4691123 , 0.71713666, -0.5090585 ], | ||
| [-0.13563237, 2.21211203, 0.82678535]]) |
There was a problem hiding this comment.
I'm a little confused by this MergeError example. Is the error raised because this merge is trying to merge two datasets that have the same variables which have the same coordinates?
There was a problem hiding this comment.
Yes, that's what this is attempting to indicate. Let me know if this is clearer....
|
@jhamman thanks for catching my lint errors -- that's a little embarrassing! My linter seems to have disabled itself, which I need to fix. |
|
@shoyer - I gave this a once over. A few minor comments in addition to my comments above,
|
|
@jhamman another look? |
|
OK, I want to get this in for v0.8.0 (and make that release soon), so I'm merging this. I think it's in significantly better shape that before, though it's certainly still more complex than ideal. |
Fixes #417
New top level :py:func:
mergefunction allows for combining variables from any number ofDatasetand/orDataArrayvariables.Example usage:
The internal refactoring also lays the ground work for supporting ufunc-like functions that merge three or more arguments, such as the full form of
where.Notes to any potential reviewers:
This doesn't have as much test coverage as I would like, but I did get all the existing functionality working. I'll see if I can add in some more tests for the internal code in
merge.py. Also, more docstrings is probably a good idea.Either way, I'm a bit nervous that I haven't broken things, because frankly I still don't understand exactly how the old code worked (and yes, I wrote it!). So we should probably make a release candidate for xarray v0.8 to avoid the need for a bug fix release shortly afterwards.
cc @jhamman @MaximilianR