home / github

Menu
  • Search all tables
  • GraphQL API

issues

Table actions
  • GraphQL API for issues

1 row where comments = 22, repo = 13221727 and user = 1217238 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

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

type 1

  • pull 1

state 1

  • closed 1

repo 1

  • xarray · 1 ✖
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
252358450 MDExOlB1bGxSZXF1ZXN0MTM3Mjc0Nzgx 1517 Automatic parallelization for dask arrays in apply_ufunc shoyer 1217238 closed 0     22 2017-08-23T17:27:36Z 2017-10-09T23:28:52Z 2017-10-09T23:26:06Z MEMBER   0 pydata/xarray/pulls/1517

This lets you parallelize a function designed for numpy inputs just by adding a few keyword arguments to apply_ufunc.

Example usage, to calculate rank correlation between two variables (this will probably turn into an example for the docs): ```python import numpy as np import xarray as xr import bottleneck

def covariance_gufunc(x, y): return ((x - x.mean(axis=-1, keepdims=True)) * (y - y.mean(axis=-1, keepdims=True))).mean(axis=-1)

def correlation_gufunc(x, y): return covariance_gufunc(x, y) / (x.std(axis=-1) * y.std(axis=-1))

def spearman_correlation_gufunc(x, y): x_ranks = bottleneck.rankdata(x, axis=-1) y_ranks = bottleneck.rankdata(y, axis=-1) return correlation_gufunc(x_ranks, y_ranks)

def spearman_correlation(x, y, dim): return xr.core.compuation.apply_ufunc( spearman_correlation_gufunc, x, y, input_core_dims=[[dim], [dim]], dask='parallelized', output_dtypes=[float]) We get a nice 5x speedup for this compute bound task: In [56]: rs = np.random.RandomState(0)

In [57]: array1 = xr.DataArray(rs.randn(1000, 100000), dims=['place', 'time']) # 800MB

In [58]: array2 = array1 + 0.5 * rs.randn(1000, 100000)

using one core, on numpy arrays

In [61]: %time _ = spearman_correlation(array1, array2, 'time') CPU times: user 21.6 s, sys: 2.84 s, total: 24.5 s Wall time: 24.9 s

using all my laptop's cores, with dask

In [63]: r = spearman_correlation(array1.chunk({'place': 10}), array2.chunk({'place': 10}), 'time')

In [64]: %time _ = r.compute() CPU times: user 30.9 s, sys: 1.74 s, total: 32.6 s Wall time: 4.59 s ```

Still needs examples in the documentation.

The next step is finally expose apply_ufunc as public API :).

  • [x] Closes #585
  • [x] Tests added / passed
  • [x] Passes git diff upstream/master | flake8 --diff
  • [x] Fully documented, including whats-new.rst for all changes and api.rst for new API

cc @mrocklin

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

Advanced export

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

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 1555.223ms · About: xarray-datasette