home / github

Menu
  • GraphQL API
  • Search all tables

issue_comments

Table actions
  • GraphQL API for issue_comments

4 rows where author_association = "MEMBER", issue = 307783090 and user = 10194086 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 1

  • mathause · 4 ✖

issue 1

  • rolling: allow control over padding · 4 ✖

author_association 1

  • MEMBER · 4 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
747376047 https://github.com/pydata/xarray/issues/2007#issuecomment-747376047 https://api.github.com/repos/pydata/xarray/issues/2007 MDEyOklzc3VlQ29tbWVudDc0NzM3NjA0Nw== mathause 10194086 2020-12-17T11:14:33Z 2020-12-17T16:02:25Z MEMBER

I just need to find the three warmest consecutive months from a temperature dataset for my work, so I thought I add a complete example. First, create an example dataset with monthly temperature:

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

time = pd.date_range("2000", periods=12 * 30, freq="M") temp = np.sin((time.month - 5) / 6 * np.pi) + np.random.randn(*time.shape) * 0.3 da = xr.DataArray(temp, dims=["time"], coords=dict(time=time)) print(da) ```

python <xarray.DataArray (time: 360)> array([-0.676731, -0.812742, -1.367547, ..., 0.186731, 0.237676, -0.343879]) Coordinates: * time (time) datetime64[ns] 2000-01-31 2000-02-29 ... 2029-12-31

Currently we can achieve this like:

```python n_months = 3

monthly = da.groupby("time.month").mean() padded = monthly.pad(month=n_months, mode="wrap") rolled = padded.rolling(center=True, month=n_months).mean(skipna=False) sliced = rolled.isel(month=slice(3, -3))

central_month = sliced.idxmax() ```

Implementing pad_mode in rolling would allow to do:

```python monthly = da.groupby("time.month").mean() rolled = monthly.rolling(center=True, month=n_months, pad_mode="wrap").mean(skipna=False)

central_month = rolled.idxmax() ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  rolling: allow control over padding 307783090
499548285 https://github.com/pydata/xarray/issues/2007#issuecomment-499548285 https://api.github.com/repos/pydata/xarray/issues/2007 MDEyOklzc3VlQ29tbWVudDQ5OTU0ODI4NQ== mathause 10194086 2019-06-06T15:36:58Z 2019-06-06T15:36:58Z MEMBER

I am coming back to @shoyer suggestion in #2011 - your idea would be to do first a pad and then a rolling operation as e.g.:

``` python

import numpy as np import xarray as xr

x = np.arange(1, 366) y = np.random.randn(365) ds = xr.DataArray(y, dims=dict(dayofyear=x))

ds.pad(dayofyear=15, mode='wrap').rolling(center=True, dayofyear=31).mean()

```

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  rolling: allow control over padding 307783090
375455202 https://github.com/pydata/xarray/issues/2007#issuecomment-375455202 https://api.github.com/repos/pydata/xarray/issues/2007 MDEyOklzc3VlQ29tbWVudDM3NTQ1NTIwMg== mathause 10194086 2018-03-22T20:57:59Z 2018-03-22T20:57:59Z MEMBER

I think what I want is like the filter function in R with circular=True.

I found two possibilities but they are quite "hand made" and certainly not very efficient

Solution with slicing: ``` python

take the last and first elements and append/ prepend them

first = ds[:15] last = ds[-15:] extended = xr.concat([last, ds, first], 'dayofyear')

do the rolling on the extended ds and get rid of NaNs

sol1 = extended.rolling(dayofyear=31, center=True).mean().dropna('dayofyear') ```

Solution with roll: python roll1 = ds.roll(dayofyear=150).rolling(dayofyear=31, center=True).mean() roll2 = ds.rolling(dayofyear=31, center=True).mean() sol2 = xr.concat([roll1, roll2], dim='r').mean('r') Call rolling on original and rolled dataset, and put them together again.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  rolling: allow control over padding 307783090
375445915 https://github.com/pydata/xarray/issues/2007#issuecomment-375445915 https://api.github.com/repos/pydata/xarray/issues/2007 MDEyOklzc3VlQ29tbWVudDM3NTQ0NTkxNQ== mathause 10194086 2018-03-22T20:26:24Z 2018-03-22T20:27:59Z MEMBER

Probably a mix of both - I want to compute a moving average, but with periodic boundaries. rolling sets window_length - 1 elements to nan. However I want to calculate these like so:

running_mean_0 = xr.concat([ds[-15:], ds[:16]]).mean()
running_mean_1 = xr.concat([ds[-14:], ds[:17]]).mean()

and so on...

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  rolling: allow control over padding 307783090

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