-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Should str.format() work on xarray scalars? #5976
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
Comments
Allowing Separate point but FWIW I generally use |
@fmaussion how would you envision this working for non-scalar arrays? Would it just raise? |
Yes, similar to numpy: da = xr.DataArray([1, 2, 3]).data
print(f'{da}')
print(f'{da:d}')
[1 2 3]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-93-e6dbd8f1cf00> in <module>
1 da = xr.DataArray([1, 2, 3]).data
2 print(f'{da}')
----> 3 print(f'{da:d}')
TypeError: unsupported format string passed to numpy.ndarray.__format__ |
Uh oh!
There was an error while loading. Please reload this page.
Consider:
Which outputs:
And the numpy equivalent:
I always found the xarray scalar output to be a bit unfriendly for beginners. In my classes very often scalars are the last output of a computation, and the fact that we can't format the relatively verbose xarray output without resulting to the
.data
trick is a bit confusing for students (but I agree this is a detail).Is there a way to get
print(f'{da[0]:d}')
to work? Thoughts?The text was updated successfully, but these errors were encountered: