home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

7 rows where issue = 415209776 sorted by updated_at descending

✖
✖

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date)

user 3

  • yohai 3
  • shoyer 2
  • fujiisoup 2

author_association 2

  • MEMBER 4
  • CONTRIBUTOR 3

issue 1

  • formatting of singleton DataArrays · 7 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
471136862 https://github.com/pydata/xarray/issues/2791#issuecomment-471136862 https://api.github.com/repos/pydata/xarray/issues/2791 MDEyOklzc3VlQ29tbWVudDQ3MTEzNjg2Mg== yohai 6164157 2019-03-09T02:14:53Z 2019-03-09T02:15:40Z CONTRIBUTOR

To make things concrete, the solution that I have in mind is as simple as adding this function to DataArray:

python def __format__(self, format_spec): return self.values.__format__(format_spec)

Here's one use case I have encountered: python ds=xr.Dataset({'A':(['x','y','z'], np.random.rand(40,40,3)), 'B':(['z'], np.random.randn(3))}, coords={'z':[31,42,45]}) fg=ds.A.plot(col='z') for ax, d in zip(fg.axes.flat, fg.name_dicts.flat): t=ax.get_title() ax.set_title('{} and B(z)={:1.2}'.format(t, ds.sel(**d).B))

This way, if you want to vectorize a __format__ on an array can you not simply do ```python ar = xr.DataArray([39, 103, id(xr)]) print('{:3.3f} {:3.3e} {:x}'.format(*ar))

prints 39.000 1.030e+02 10e5bb548

```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  formatting of singleton DataArrays 415209776
470801183 https://github.com/pydata/xarray/issues/2791#issuecomment-470801183 https://api.github.com/repos/pydata/xarray/issues/2791 MDEyOklzc3VlQ29tbWVudDQ3MDgwMTE4Mw== yohai 6164157 2019-03-08T04:30:22Z 2019-03-08T04:30:22Z CONTRIBUTOR

I tend towards the former, to coerce singleton arrays to behave as scalars of their dytpe. I think it makes more sense in terms of use cases (at least everything that I needed). I don't mind implementing it if there is agreement as to which of the two to do.

These behaviors would definitely conflict for scalar objects -- in the second case, we would still want to include some indication that it's an xarray.DataArray. NumPy doesn't have a conflict because indexing an array results in a NumPy scalars, which prints like Python builtin scalars.

@shoyer I don't see why would that be the case. If I format something as '{:04d} {:3.5e} {:2.3E}'.format(dataarray) or whatnot, I would expect that the average user would expect to get '0043 4.35000e+02 2.450E+02' in return, without any indication that these are data arrays.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  formatting of singleton DataArrays 415209776
469437857 https://github.com/pydata/xarray/issues/2791#issuecomment-469437857 https://api.github.com/repos/pydata/xarray/issues/2791 MDEyOklzc3VlQ29tbWVudDQ2OTQzNzg1Nw== fujiisoup 6815844 2019-03-04T21:57:04Z 2019-03-04T21:57:04Z MEMBER

@yohai , sorry, I misunderstood __format__ and __repr__. I like shoyer's

vectorize format() over each element of the array (the proposal in the linked numpy issue)

as I feel it more consistent with the existing xarray __repr__.

I sometimes want a 0d-dataarray to behave as a native scalar. format is one of a typical case, but there are several other cases, e.g., np.ones(xr.DataArray([0])[0]). Therefore, I always needs to be carefule whether the scalar is xarray object or not.

I am a bit worrying if printing 0d-dataarray as a scalar would confuse me as it is a scalar not a 0d-array.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  formatting of singleton DataArrays 415209776
469325571 https://github.com/pydata/xarray/issues/2791#issuecomment-469325571 https://api.github.com/repos/pydata/xarray/issues/2791 MDEyOklzc3VlQ29tbWVudDQ2OTMyNTU3MQ== shoyer 1217238 2019-03-04T16:48:03Z 2019-03-04T16:48:03Z MEMBER

Here's a related NumPy issue: https://github.com/numpy/numpy/issues/5543

I guess there are two possible behaviors for '{:d}'.format(x) where x is a DataArray object: - coerce scalar arrays to native Python numbers and format it like a float - vectorize format() over each element of the array (the proposal in the linked numpy issue)

These behaviors would definitely conflict for scalar objects -- in the second case, we would still want to include some indication that it's an xarray.DataArray. NumPy doesn't have a conflict because indexing an array results in a NumPy scalars, which prints like Python builtin scalars.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  formatting of singleton DataArrays 415209776
469320419 https://github.com/pydata/xarray/issues/2791#issuecomment-469320419 https://api.github.com/repos/pydata/xarray/issues/2791 MDEyOklzc3VlQ29tbWVudDQ2OTMyMDQxOQ== yohai 6164157 2019-03-04T16:35:09Z 2019-03-04T16:35:44Z CONTRIBUTOR

On the one hand I agree, but note that the same behavior works for numpy arrays

```python import numpy as np a=np.array([1,2,3,4]) ' '.join('{:d}'.format(v) for v in a)

prints '1 2 3 4'

```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  formatting of singleton DataArrays 415209776
469160334 https://github.com/pydata/xarray/issues/2791#issuecomment-469160334 https://api.github.com/repos/pydata/xarray/issues/2791 MDEyOklzc3VlQ29tbWVudDQ2OTE2MDMzNA== fujiisoup 6815844 2019-03-04T08:23:42Z 2019-03-04T08:23:42Z MEMBER

I agree that it is a bit annoying that 1d DataArray prints much information especially we want to embed the value into a string. However, I'm a bit worried whether it would be surprising if an object that looks a native scalar is actually an xr.DataArray of one element, especially when working in an interactive environment.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  formatting of singleton DataArrays 415209776
469155529 https://github.com/pydata/xarray/issues/2791#issuecomment-469155529 https://api.github.com/repos/pydata/xarray/issues/2791 MDEyOklzc3VlQ29tbWVudDQ2OTE1NTUyOQ== shoyer 1217238 2019-03-04T08:05:53Z 2019-03-04T08:05:53Z MEMBER

Yes, I think this would be a nice addition. This would entail implementing a __format__ method on xarray.DataArray: https://docs.python.org/3/reference/datamodel.html#object.format

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  formatting of singleton DataArrays 415209776

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issue_comments] (
   [html_url] TEXT,
   [issue_url] TEXT,
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [created_at] TEXT,
   [updated_at] TEXT,
   [author_association] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [issue] INTEGER REFERENCES [issues]([id])
);
CREATE INDEX [idx_issue_comments_issue]
    ON [issue_comments] ([issue]);
CREATE INDEX [idx_issue_comments_user]
    ON [issue_comments] ([user]);
Powered by Datasette · Queries took 27.613ms · About: xarray-datasette
  • Sort ascending
  • Sort descending
  • Facet by this
  • Hide this column
  • Show all columns
  • Show not-blank rows