home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1051772149

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
1051772149 PR_kwDOAMm_X84ucj1i 5981 Allow string formatting of scalar DataArrays 10050469 closed 0     4 2021-11-12T09:44:43Z 2022-05-09T15:25:25Z 2022-05-09T15:25:02Z MEMBER   0 pydata/xarray/pulls/5981
  • [x] Closes https://github.com/pydata/xarray/issues/5976
  • [x] Tests added
  • [x] Passes pre-commit run --all-files
  • [ ] User visible changes (including notable bug fixes) are documented in whats-new.rst

This is a first try at formatting dataarray scalars. Here is the current behavior:

```python In [1]: import xarray as xr ...: import numpy as np

In [2]: a = np.array(1) ...: da = xr.DataArray(a)

In [3]: print(a) 1

In [4]: print(da) <xarray.DataArray ()> array(1)

In [5]: print('{}'.format(a)) 1

In [6]: print('{}'.format(da)) <xarray.DataArray ()> array(1)

In [7]: print('{:.3f}'.format(a)) 1.000

In [8]: print('{:.3f}'.format(da)) 1.000

In [9]: a = np.array([1, 2]) ...: da = xr.DataArray(a)

In [10]: print('{}'.format(a)) [1 2]

In [11]: print('{}'.format(da)) <xarray.DataArray (dim_0: 2)> array([1, 2]) Dimensions without coordinates: dim_0

In [12]: print('{:.3f}'.format(a))

TypeError Traceback (most recent call last) <ipython-input-12-c5afc7863e89> in <module> ----> 1 print('{:.3f}'.format(a))

TypeError: unsupported format string passed to numpy.ndarray.format

In [13]: print('{:.3f}'.format(da))

TypeError Traceback (most recent call last) <ipython-input-13-bddebd8462bd> in <module> ----> 1 print('{:.3f}'.format(da))

~/disk/Dropbox/HomeDocs/git/xarray/xarray/core/common.py in format(self, format_spec) 162 return formatting.array_repr(self) 163 # Else why fall back to numpy --> 164 return self.values.format(format_spec) 165 166 def _iter(self: Any) -> Iterator[Any]:

TypeError: unsupported format string passed to numpy.ndarray.format ``` I don't think there is any backwards compatibility issue but lets see if the tests pass

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

Links from other tables

  • 1 row from issues_id in issues_labels
  • 4 rows from issue in issue_comments
Powered by Datasette · Queries took 802.716ms · About: xarray-datasette