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/1151#issuecomment-269600582,https://api.github.com/repos/pydata/xarray/issues/1151,269600582,MDEyOklzc3VlQ29tbWVudDI2OTYwMDU4Mg==,6213168,2016-12-29T09:02:36Z,2016-12-29T09:05:48Z,MEMBER,"I just realised that xarray today already implements meaningful logic when concatenating between a and c in my example above - both on an existing dimension as well as on a new one. It's just a and b that don't work. I agree that defaulting to NaN would be a good option (regardless if the dimension is new or existing).
So to recap, when concatenating [a, b, c], where b does not have the y coord:
- if the dtype of the y coord in both a and c is float, numpy.float32, or numpy.float64, fill in with NaN
- if it's any datetime format, fill in with NaT
- if it's strings, fill in with empty string??
- in any other case, convert everything to object and fill in with None
Correct?
Is there any helper function to facilitate this?
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,193294569
https://github.com/pydata/xarray/issues/1151#issuecomment-269478770,https://api.github.com/repos/pydata/xarray/issues/1151,269478770,MDEyOklzc3VlQ29tbWVudDI2OTQ3ODc3MA==,6213168,2016-12-28T13:43:55Z,2016-12-28T13:43:55Z,MEMBER,"@shoyer the end goal is to replicate in concat() the same behaviour you already hav in \_\_add\_\_ and \_\_mul\_\_.
So take for example
```
a = xarray.DataArray([1, 2, 3], dims=['x'], coords={'y': 10})
b = xarray.DataArray([4, 5, 6], dims=['x'])
c = xarray.DataArray([7, 8, 9], dims=['x'], coords={'y': 20})
```
a+b -> y is propagated to the result (unambiguous)
a+c -> y is discarded (ambiguous)
I suppose I could look at how this happens in \_\_add\_\_ and move the logic up into broadcast() (which \_\_add\_\_ should already invoke)?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,193294569
https://github.com/pydata/xarray/issues/1151#issuecomment-269089778,https://api.github.com/repos/pydata/xarray/issues/1151,269089778,MDEyOklzc3VlQ29tbWVudDI2OTA4OTc3OA==,6213168,2016-12-24T15:57:27Z,2016-12-24T15:57:27Z,MEMBER,"I updated the code and tested it in my project - it works fine.
Any suggestions before I start integrating it inside xarray.broadcast()?
```
def broadcast_scalar_coords(*args, exclude=()):
""""""Broadcast scalar coords whenever they're unambiguous,
and remove them when they are ambiguous.
This allows replicating the behaviour of addition
or moltiplication of xarrays in concatenation.
""""""
unambiguous = {}
ambiguous = set()
for arg in args:
for k, v in arg.coords.items():
if k in exclude:
continue
# non-scalar coords are automatically ambiguous
if v.shape == ():
if k not in ambiguous:
v = v.values.tolist()
if unambiguous.get(k, v) != v:
del unambiguous[k]
ambiguous.add(k)
else:
unambiguous[k] = v
else:
ambiguous.add(k)
unambiguous.pop(k, None)
args = tuple(arg.copy(deep=False) for arg in args)
for arg in args:
for k, v in unambiguous.items():
arg.coords[k] = v
for k in ambiguous:
if k in arg.coords and arg.coords[k].shape == ():
del arg.coords[k]
return args
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,193294569
https://github.com/pydata/xarray/issues/1151#issuecomment-264912356,https://api.github.com/repos/pydata/xarray/issues/1151,264912356,MDEyOklzc3VlQ29tbWVudDI2NDkxMjM1Ng==,6213168,2016-12-05T17:05:34Z,2016-12-24T15:56:15Z,MEMBER,"I wrote down this.
1. should I simply add it to xarray.broadcast()?
2. can you spot any logical flaws?
3. suggestions for cleaner code?
[edit] removed obsolete code","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,193294569