home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 258294667

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/1072#issuecomment-258294667 https://api.github.com/repos/pydata/xarray/issues/1072 258294667 MDEyOklzc3VlQ29tbWVudDI1ODI5NDY2Nw== 5572303 2016-11-03T22:35:47Z 2016-11-03T22:35:47Z CONTRIBUTOR

Here's my somewhat hacky stab at it, not optimized for speed/efficiency:

def combine_first(left, right): """ Takes 2 data arrays, performs an outer-concat, using values from the right array to fill in for missing coordinates in the left array. """ l_aligned, r_aligned = xr.align(left, right, join="outer") temp = l_aligned + r_aligned # hack temp.values[temp.notnull().values] = np.nan # now template is all nan # insert non-nan values from right array first temp.values[r_aligned.notnull().values] = r_aligned.values[r_aligned.notnull().values] # insert values from left array, overwriting those from right array temp.values[l_aligned.notnull().values] = l_aligned.values[l_aligned.notnull().values] return temp

And the result:

```

ar1 = xr.DataArray([4,5,6],[('x',[1,2,3])]) ar2 = xr.DataArray([[7,8,9],[10,11,12],[13,14,15]],[('x',[1,12,13]),('y',[0,5,6])]) ar1 <xarray.DataArray (x: 3)> array([4, 5, 6]) Coordinates: * x (x) int64 1 2 3 ar2 <xarray.DataArray (x: 3, y: 3)> array([[ 7, 8, 9], [10, 11, 12], [13, 14, 15]]) Coordinates: * x (x) int64 1 12 13 * y (y) int64 0 5 6 temp = combine_first(ar1, ar2) temp <xarray.DataArray (x: 5, y: 3)> array([[ 4., 5., 6.], [ 4., 5., 6.], [ 4., 5., 6.], [ 10., 11., 12.], [ 13., 14., 15.]]) Coordinates: * x (x) int64 1 2 3 12 13 * y (y) int64 0 5 6 temp = combine_first(ar2, ar1) temp <xarray.DataArray (x: 5, y: 3)> array([[ 7., 8., 9.], [ 4., 5., 6.], [ 4., 5., 6.], [ 10., 11., 12.], [ 13., 14., 15.]]) Coordinates: * x (x) int64 1 2 3 12 13 * y (y) int64 0 5 6 ```

Would this be the behavior we want from xarray's combine_first? Not entirely analogous to the Pandas function. Maybe rename it?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  186680248
Powered by Datasette · Queries took 0.773ms · About: xarray-datasette