Skip to content

avoiding nans from coordinate union in dataset #6731

Answered by andersy005
tylerflex asked this question in Q&A
Discussion options

You must be logged in to vote

Not 100% sure this is what you are looking for, but you could use xr.merge() in conjunction with join='exact or join='inner'

In [13]: import xarray as xr
    ...: print(f'xarray version = {xr.__version__}')
    ...: x1 = [-1, 0, 1]
    ...: x2 = [-0.5, 0.5]
    ...: ds1 = xr.DataArray(np.random.random(len(x1)), coords=dict(x=x1)).to_dataset(name='d1')
    ...: ds2 = xr.DataArray(np.random.random(len(x2)), coords=dict(x=x2)).to_dataset(name='d2')
xarray version = 2022.3.0

In [26]: ds1
Out[26]: 
<xarray.Dataset>
Dimensions:  (x: 3)
Coordinates:
  * x        (x) int64 -1 0 1
Data variables:
    d1       (x) float64 0.9725 0.184 0.6954

In [27]: ds2
Out[27]: 
<xarray.Dataset>
Dimensions:  (x: 2

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by dcherian
Comment options

You must be logged in to vote
3 replies
@andersy005
Comment options

@tylerflex
Comment options

@dcherian
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants