home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 1316549018

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
1316549018 PR_kwDOAMm_X848Bm7B 6823 Rely on array backend for string formatting 14371165 closed 0     5 2022-07-25T09:43:21Z 2022-08-08T15:11:34Z 2022-08-08T15:11:34Z MEMBER   0 pydata/xarray/pulls/6823
  • Rely on array backend for string formatting instead of forcing to numpy arrays. The previous implementation used .values to force to numpy arrays which doesn't work for sparse arrays and might be scary in the case of large dask arrays.
  • Only allow format_spec when dealing with scalar arrays, shape=(). Using f-strings is a common method to print the repr. If we want to have full support of .__format__ we should probably add format_spec as input to formatting.array_repr.

  • [x] Closes #6822

  • [x] Tests added
  • [x] User visible changes (including notable bug fixes) are documented in whats-new.rst

```python import pandas as pd import xarray as xr

s = pd.Series( range(4), index=pd.MultiIndex.from_product([list("ab"), list("cd")]), )

da = xr.DataArray.from_series(s, sparse=True)

Handle sparse:

print(f"Error: {da} is sparse") Error: <xarray.DataArray (level_0: 2, level_1: 2)> <COO: shape=(2, 2), dtype=float64, nnz=4, fill_value=nan> Coordinates: * level_0 (level_0) object 'a' 'b' * level_1 (level_1) object 'c' 'd' is sparse

Handle format_spec:

da = xr.DataArray([1, 2, 3])

print(f'{da[0]}') <xarray.DataArray ()> array(1)

print(f'{da[0]:d}') 1

print(f'{da[0]:f}') 1.000000

da = xr.DataArray([1, 2, 3]) print(f'{da:.f}') Traceback (most recent call last): (...) NotImplementedError: Using format_spec is only supported when shape is (). Got shape = (3,). ```

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

Links from other tables

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