home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

5 rows where issue = 1350803561 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

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

user 3

  • mathause 2
  • st-bender 2
  • dcherian 1

author_association 2

  • MEMBER 3
  • CONTRIBUTOR 2

issue 1

  • DataArray.resample().apply() fails to apply custom function · 5 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
1230234269 https://github.com/pydata/xarray/issues/6953#issuecomment-1230234269 https://api.github.com/repos/pydata/xarray/issues/6953 IC_kwDOAMm_X85JU-Kd st-bender 28786187 2022-08-29T12:41:47Z 2022-08-29T12:41:47Z CONTRIBUTOR

Hi @mathause

It does work if the array keeps the size:

python data.resample(index="M").apply(lambda x: x.values)

Thanks, but I am not sure I find that intuitive, why should the resampled array have the same size as the original? It seems to make only sense for DataArray.apply(), but not for a resampled one. As I indicated in my other reply, returning a scalar or equivalent should be fine, shouldn't it? At the very least the documentation is lacking, it refers to the pandas method, but clearly the behaviour is different.

As a workaround you could allow your function to consume a dummy axis. Or you could pass dim as ...

python data.resample(index="M").reduce(lambda x, axis: 1) # workaround 1 data.resample(index="M").reduce(lambda x: 1, dim=...) # workaround 2

(reduce only passes axis if dim is not None but groupby passes the group_dim per default.

That feels a bit like curing the symptoms instead of the root cause, why not set dim='...' if it is not given?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  DataArray.resample().apply() fails to apply custom function 1350803561
1228461073 https://github.com/pydata/xarray/issues/6953#issuecomment-1228461073 https://api.github.com/repos/pydata/xarray/issues/6953 IC_kwDOAMm_X85JONQR mathause 10194086 2022-08-26T13:03:04Z 2022-08-26T13:03:04Z MEMBER

It does work if the array keeps the size:

python data.resample(index="M").apply(lambda x: x.values)

As a workaround you could allow your function to consume a dummy axis. Or you could pass dim as ...

python data.resample(index="M").reduce(lambda x, axis: 1) # workaround 1 data.resample(index="M").reduce(lambda x: 1, dim=...) # workaround 2

(reduce only passes axis if dim is not None but groupby passes the group_dim per default.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  DataArray.resample().apply() fails to apply custom function 1350803561
1228267515 https://github.com/pydata/xarray/issues/6953#issuecomment-1228267515 https://api.github.com/repos/pydata/xarray/issues/6953 IC_kwDOAMm_X85JNd_7 st-bender 28786187 2022-08-26T09:22:21Z 2022-08-26T09:22:21Z CONTRIBUTOR

@mathause Thanks, that works for np.median, but .reduce() passes an axis= keyword argument, which needs to be taken care of by any custom function. I used np.median here just as an example, as it showed the problem.

@dcherian I am not sure if raising an error would be very user friendly. In my opinion, which may be biased by my personal use cases, I would expect .apply() (or .map() for that matter) of a resample object to take any function that returns a scalar: the value at the resampled point. It should be then up to xarray to iterate over any other non-resampled dimensions. I am not sure why it requires to return a DataArray in the first place. As mentioned, it works with pandas series and dataframes, e.g.:

python data.to_pandas().resample("M").apply(np.median)

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  DataArray.resample().apply() fails to apply custom function 1350803561
1227374907 https://github.com/pydata/xarray/issues/6953#issuecomment-1227374907 https://api.github.com/repos/pydata/xarray/issues/6953 IC_kwDOAMm_X85JKEE7 dcherian 2448579 2022-08-25T14:56:35Z 2022-08-25T14:56:35Z MEMBER

1114 applied_example, applied = peek_at(applied)

We could raise an error here if applied_example is not a DataArray or Dataset but not sure if its worth it. This is a somewhat common user question

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  DataArray.resample().apply() fails to apply custom function 1350803561
1227218693 https://github.com/pydata/xarray/issues/6953#issuecomment-1227218693 https://api.github.com/repos/pydata/xarray/issues/6953 IC_kwDOAMm_X85JJd8F mathause 10194086 2022-08-25T12:53:32Z 2022-08-25T12:53:32Z MEMBER

apply seems to expect that the applied function returns a DataArray. As an alternative could you use data.resample(index="M").reduce(np.median)?

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  DataArray.resample().apply() fails to apply custom function 1350803561

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 13.768ms · About: xarray-datasette