Skip to content

Commit 08911b9

Browse files
committed
Merge remote-tracking branch 'upstream/main' into groupby-aggs-using-numpy-groupies
* upstream/main: Add groupby & resample benchmarks (pydata#5922) Fix plot.line crash for data of shape (1, N) in _title_for_slice on format_item (pydata#5948) Disable unit test comments (pydata#5946) Publish test results from workflow_run only (pydata#5947)
2 parents a2168df + 20fddb7 commit 08911b9

File tree

6 files changed

+93
-37
lines changed

6 files changed

+93
-37
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,12 @@ jobs:
108108
name: codecov-umbrella
109109
fail_ci_if_error: false
110110

111-
publish-test-results:
112-
needs: test
111+
event_file:
112+
name: "Event File"
113113
runs-on: ubuntu-latest
114-
# the build-and-test job might be skipped, we don't need to run this job then
115-
if: success() || failure()
116-
117114
steps:
118-
- name: Download Artifacts
119-
uses: actions/download-artifact@v2
120-
with:
121-
path: test-results
122-
123-
- name: Publish Unit Test Results
124-
uses: EnricoMi/publish-unit-test-result-action@v1
115+
- name: Upload
116+
uses: actions/upload-artifact@v2
125117
with:
126-
files: test-results/**/*.xml
118+
name: Event File
119+
path: ${{ github.event_path }}
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copied from https://github.com/EnricoMi/publish-unit-test-result-action/blob/v1.18/README.md#support-fork-repositories-and-dependabot-branches
1+
# Copied from https://github.com/EnricoMi/publish-unit-test-result-action/blob/v1.23/README.md#support-fork-repositories-and-dependabot-branches
22

33
name: Publish test results
44

@@ -12,11 +12,7 @@ jobs:
1212
publish-test-results:
1313
name: Publish test results
1414
runs-on: ubuntu-latest
15-
if: >
16-
github.event.workflow_run.conclusion != 'skipped' && (
17-
github.event.sender.login == 'dependabot[bot]' ||
18-
github.event.workflow_run.head_repository.full_name != github.repository
19-
)
15+
if: github.event.workflow_run.conclusion != 'skipped'
2016

2117
steps:
2218
- name: Download and extract artifacts
@@ -26,13 +22,10 @@ jobs:
2622
mkdir artifacts && cd artifacts
2723
2824
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
29-
artifacts=$(gh api $artifacts_url -q '.artifacts[] | {name: .name, url: .archive_download_url}')
3025
31-
IFS=$'\n'
32-
for artifact in $artifacts
26+
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
3327
do
34-
name=$(jq -r .name <<<$artifact)
35-
url=$(jq -r .url <<<$artifact)
28+
IFS=$'\t' read name url <<< "$artifact"
3629
gh api $url > "$name.zip"
3730
unzip -d "$name" "$name.zip"
3831
done
@@ -41,4 +34,7 @@ jobs:
4134
uses: EnricoMi/publish-unit-test-result-action@v1
4235
with:
4336
commit: ${{ github.event.workflow_run.head_sha }}
37+
event_file: artifacts/Event File/event.json
38+
event_name: ${{ github.event.workflow_run.event }}
4439
files: "artifacts/**/*.xml"
40+
comment_mode: off

asv_bench/benchmarks/groupby.py

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,98 @@
11
import numpy as np
2+
import pandas as pd
23

34
import xarray as xr
45

5-
from . import parameterized, requires_dask
6+
from . import _skip_slow, parameterized, requires_dask
67

78

89
class GroupBy:
910
def setup(self, *args, **kwargs):
10-
self.ds = xr.Dataset(
11+
self.n = 100
12+
self.ds1d = xr.Dataset(
1113
{
12-
"a": xr.DataArray(np.r_[np.arange(500.0), np.arange(500.0)]),
13-
"b": xr.DataArray(np.arange(1000.0)),
14+
"a": xr.DataArray(np.r_[np.repeat(1, self.n), np.repeat(2, self.n)]),
15+
"b": xr.DataArray(np.arange(2 * self.n)),
1416
}
1517
)
18+
self.ds2d = self.ds1d.expand_dims(z=10)
1619

17-
@parameterized(["method"], [("sum", "mean")])
18-
def time_agg(self, method):
19-
return getattr(self.ds.groupby("a"), method)()
20+
@parameterized(["ndim"], [(1, 2)])
21+
def time_init(self, ndim):
22+
getattr(self, f"ds{ndim}d").groupby("b")
23+
24+
@parameterized(["method", "ndim"], [("sum", "mean"), (1, 2)])
25+
def time_agg_small_num_groups(self, method, ndim):
26+
ds = getattr(self, f"ds{ndim}d")
27+
getattr(ds.groupby("a"), method)()
28+
29+
@parameterized(["method", "ndim"], [("sum", "mean"), (1, 2)])
30+
def time_agg_large_num_groups(self, method, ndim):
31+
ds = getattr(self, f"ds{ndim}d")
32+
getattr(ds.groupby("b"), method)()
2033

2134

2235
class GroupByDask(GroupBy):
2336
def setup(self, *args, **kwargs):
2437
requires_dask()
2538
super().setup(**kwargs)
26-
self.ds = self.ds.chunk({"dim_0": 50})
39+
self.ds1d = self.ds1d.sel(dim_0=slice(None, None, 2)).chunk({"dim_0": 50})
40+
self.ds2d = self.ds2d.sel(dim_0=slice(None, None, 2)).chunk(
41+
{"dim_0": 50, "z": 5}
42+
)
2743

2844

29-
class GroupByDataFrame(GroupBy):
45+
class GroupByPandasDataFrame(GroupBy):
46+
"""Run groupby tests using pandas DataFrame."""
47+
3048
def setup(self, *args, **kwargs):
49+
# Skip testing in CI as it won't ever change in a commit:
50+
_skip_slow()
51+
3152
super().setup(**kwargs)
32-
self.ds = self.ds.to_dataframe()
53+
self.ds1d = self.ds1d.to_dataframe()
3354

3455

3556
class GroupByDaskDataFrame(GroupBy):
57+
"""Run groupby tests using dask DataFrame."""
58+
59+
def setup(self, *args, **kwargs):
60+
# Skip testing in CI as it won't ever change in a commit:
61+
_skip_slow()
62+
63+
requires_dask()
64+
super().setup(**kwargs)
65+
self.ds1d = self.ds1d.chunk({"dim_0": 50}).to_dataframe()
66+
67+
68+
class Resample:
69+
def setup(self, *args, **kwargs):
70+
self.ds1d = xr.Dataset(
71+
{
72+
"b": ("time", np.arange(365.0 * 24)),
73+
},
74+
coords={"time": pd.date_range("2001-01-01", freq="H", periods=365 * 24)},
75+
)
76+
self.ds2d = self.ds1d.expand_dims(z=10)
77+
78+
@parameterized(["ndim"], [(1, 2)])
79+
def time_init(self, ndim):
80+
getattr(self, f"ds{ndim}d").resample(time="D")
81+
82+
@parameterized(["method", "ndim"], [("sum", "mean"), (1, 2)])
83+
def time_agg_small_num_groups(self, method, ndim):
84+
ds = getattr(self, f"ds{ndim}d")
85+
getattr(ds.resample(time="3M"), method)()
86+
87+
@parameterized(["method", "ndim"], [("sum", "mean"), (1, 2)])
88+
def time_agg_large_num_groups(self, method, ndim):
89+
ds = getattr(self, f"ds{ndim}d")
90+
getattr(ds.resample(time="48H"), method)()
91+
92+
93+
class ResampleDask(Resample):
3694
def setup(self, *args, **kwargs):
3795
requires_dask()
3896
super().setup(**kwargs)
39-
self.ds = self.ds.chunk({"dim_0": 50}).to_dataframe()
97+
self.ds1d = self.ds1d.chunk({"time": 50})
98+
self.ds2d = self.ds2d.chunk({"time": 50, "z": 4})

doc/whats-new.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Deprecations
3434

3535
Bug fixes
3636
~~~~~~~~~
37-
37+
- Fix plot.line crash for data of shape ``(1, N)`` in _title_for_slice on format_item (:pull:`5948`).
38+
By `Sebastian Weigand <https://github.com/s-weigand>`_.
3839

3940
Documentation
4041
~~~~~~~~~~~~~

xarray/core/formatting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def format_item(x, timedelta_format=None, quote_strings=True):
143143
elif isinstance(x, (str, bytes)):
144144
return repr(x) if quote_strings else x
145145
elif hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating):
146-
return f"{x:.4}"
146+
return f"{x.item():.4}"
147147
else:
148148
return str(x)
149149

xarray/tests/test_plot.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ def test_slice_in_title(self):
754754
title = plt.gca().get_title()
755755
assert "d = 10.01" == title
756756

757+
def test_slice_in_title_single_item_array(self):
758+
"""Edge case for data of shape (1, N) or (N, 1)."""
759+
darray = self.darray.expand_dims({"d": np.array([10.009])})
760+
darray.plot.line(x="period")
761+
title = plt.gca().get_title()
762+
assert "d = 10.01" == title
763+
757764

758765
class TestPlotStep(PlotTestCase):
759766
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)