New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Behavior of dataarray with no dimensions #1726
Comments
Yes, this was an intentional choice, though not without occasional regrets! This is nice from an consistency perspective: every operation on an xarray object returns another xarray object. Also, as you point out, this allows us to preserve metadata such as attributes or scalar coordinates. I'm going to mark this as a documentation issue: this would be a great thing to add our docs somewhere (maybe the FAQ page?). |
Thanks for your answer. |
I dug it a bit further. Contrary to what I said numpy is fine. If np.array(x.mean())
# -> array(2.0)
np.array([x.mean()])
# -> array([2.0])
np.array(x)
# -> ok
pd.Series(2)
# ok
pd.Series(x.mean())
# -> TypeError: len() of unsized object
pd.Series([x.mean()])
# -> dtype=object
# however for 1D x
pd.Series(x)
# dtype is fine Something looks a bit odd to me. But it looks more like a pandas issue |
Consider
The issue is that this dimensionless data array won't be cast into float by numpy/pandas when constructing a new ndarray/dataframe. You'll have to do it explicitly. Not a big deal but it feels weird.
I'm sure there's a real technical reason (keeping metadata ?) behind this behavior but I couldn't find any discussion about it.
The text was updated successfully, but these errors were encountered: