home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1051241489

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1051241489 I_kwDOAMm_X84-qKwR 5976 Should str.format() work on xarray scalars? 10050469 closed 0     3 2021-11-11T18:15:59Z 2022-07-25T20:01:29Z 2022-07-25T20:01:29Z MEMBER      

Consider:

python da = xr.DataArray([1, 2, 3]) print(f'{da[0]}') print(f'{da[0]:d}')

Which outputs:

``` <xarray.DataArray ()> array(1)


TypeError Traceback (most recent call last) <ipython-input-36-9cd7dc76455b> in <module> 1 da = xr.DataArray([1, 2, 3]) 2 print(f'{da[0]}') ----> 3 print(f'{da[0]:d}')

TypeError: unsupported format string passed to DataArray.format ``` And the numpy equivalent:

python da = xr.DataArray([1, 2, 3]).data print(f'{da[0]}') print(f'{da[0]:d}') 1 1

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?

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5976/reactions",
    "total_count": 3,
    "+1": 3,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 3 rows from issue in issue_comments
Powered by Datasette · Queries took 0.682ms · About: xarray-datasette