Skip to content

Commit ae74cc6

Browse files
committed
Merge branch 'main' into indexes-repr-join-text
2 parents bff2411 + ca57e5c commit ae74cc6

18 files changed

+292
-179
lines changed

.github/workflows/ci-additional.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v3
2626
with:
2727
fetch-depth: 2
28-
- uses: xarray-contrib/ci-trigger@v1.1
28+
- uses: xarray-contrib/ci-trigger@v1
2929
id: detect-trigger
3030
with:
3131
keyword: "[skip-ci]"

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v3
2626
with:
2727
fetch-depth: 2
28-
- uses: xarray-contrib/ci-trigger@v1.1
28+
- uses: xarray-contrib/ci-trigger@v1
2929
id: detect-trigger
3030
with:
3131
keyword: "[skip-ci]"

.github/workflows/upstream-dev-ci.yaml

Lines changed: 7 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- uses: actions/checkout@v3
2828
with:
2929
fetch-depth: 2
30-
- uses: xarray-contrib/ci-trigger@v1.1
30+
- uses: xarray-contrib/ci-trigger@v1
3131
id: detect-trigger
3232
with:
3333
keyword: "[test-upstream]"
@@ -49,8 +49,6 @@ jobs:
4949
fail-fast: false
5050
matrix:
5151
python-version: ["3.10"]
52-
outputs:
53-
artifacts_availability: ${{ steps.status.outputs.ARTIFACTS_AVAILABLE }}
5452
steps:
5553
- uses: actions/checkout@v3
5654
with:
@@ -74,110 +72,21 @@ jobs:
7472
conda info -a
7573
conda list
7674
python xarray/util/print_versions.py
77-
- name: import xarray
75+
- name: Import xarray
7876
run: |
7977
python -c 'import xarray'
8078
- name: Run Tests
8179
if: success()
8280
id: status
8381
run: |
8482
python -m pytest --timeout=60 -rf \
85-
--report-log output-${{ matrix.python-version }}-log.jsonl \
86-
|| (
87-
echo '::set-output name=ARTIFACTS_AVAILABLE::true' && false
88-
)
89-
- name: Upload artifacts
83+
--report-log output-${{ matrix.python-version }}-log.jsonl
84+
- name: Generate and publish the report
9085
if: |
9186
failure()
9287
&& steps.status.outcome == 'failure'
9388
&& github.event_name == 'schedule'
94-
&& github.repository == 'pydata/xarray'
95-
uses: actions/upload-artifact@v3
96-
with:
97-
name: output-${{ matrix.python-version }}-log.jsonl
98-
path: output-${{ matrix.python-version }}-log.jsonl
99-
retention-days: 5
100-
101-
report:
102-
name: report
103-
needs: upstream-dev
104-
if: |
105-
failure()
106-
&& github.event_name == 'schedule'
107-
&& needs.upstream-dev.outputs.artifacts_availability == 'true'
108-
runs-on: ubuntu-latest
109-
defaults:
110-
run:
111-
shell: bash
112-
steps:
113-
- uses: actions/checkout@v3
114-
- uses: actions/setup-python@v4
89+
&& github.repository_owner == 'pydata'
90+
uses: xarray-contrib/issue-from-pytest-log@v0.1
11591
with:
116-
python-version: "3.x"
117-
- uses: actions/download-artifact@v3
118-
with:
119-
path: /tmp/workspace/logs
120-
- name: Move all log files into a single directory
121-
run: |
122-
rsync -a /tmp/workspace/logs/output-*/ ./logs
123-
ls -R ./logs
124-
- name: install dependencies
125-
run: |
126-
python -m pip install pytest
127-
- name: Parse logs
128-
run: |
129-
shopt -s globstar
130-
python .github/workflows/parse_logs.py logs/**/*-log*
131-
cat pytest-logs.txt
132-
- name: Report failures
133-
uses: actions/github-script@v6
134-
with:
135-
github-token: ${{ secrets.GITHUB_TOKEN }}
136-
script: |
137-
const fs = require('fs');
138-
const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8');
139-
const title = "⚠️ Nightly upstream-dev CI failed ⚠️"
140-
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
141-
const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}`
142-
143-
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
144-
const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){
145-
repository(owner: $owner, name: $name) {
146-
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
147-
edges {
148-
node {
149-
body
150-
id
151-
number
152-
}
153-
}
154-
}
155-
}
156-
}`;
157-
158-
const variables = {
159-
owner: context.repo.owner,
160-
name: context.repo.repo,
161-
label: 'CI',
162-
creator: "github-actions[bot]"
163-
}
164-
const result = await github.graphql(query, variables)
165-
166-
// If no issue is open, create a new issue,
167-
// else update the body of the existing issue.
168-
if (result.repository.issues.edges.length === 0) {
169-
github.rest.issues.create({
170-
owner: variables.owner,
171-
repo: variables.name,
172-
body: issue_body,
173-
title: title,
174-
labels: [variables.label]
175-
})
176-
} else {
177-
github.rest.issues.update({
178-
owner: variables.owner,
179-
repo: variables.name,
180-
issue_number: result.repository.issues.edges[0].node.number,
181-
body: issue_body
182-
})
183-
}
92+
log-path: output-${{ matrix.python-version }}-log.jsonl

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
- id: mixed-line-ending
1111
# This wants to go before isort & flake8
1212
- repo: https://github.com/PyCQA/autoflake
13-
rev: "v1.7.6"
13+
rev: "v1.7.7"
1414
hooks:
1515
- id: autoflake # isort should run before black as black sometimes tweaks the isort output
1616
args: ["--in-place", "--ignore-init-module-imports"]

doc/user-guide/computation.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ and ``mean``, ``std`` and ``var`` return ``NaN``:
360360
``weights`` must be a :py:class:`DataArray` and cannot contain missing values.
361361
Missing values can be replaced manually by ``weights.fillna(0)``.
362362

363-
.. _comput.coarsen:
363+
.. _compute.coarsen:
364364

365365
Coarsen large arrays
366366
====================
367367

368368
:py:class:`DataArray` and :py:class:`Dataset` objects include a
369369
:py:meth:`~xarray.DataArray.coarsen` and :py:meth:`~xarray.Dataset.coarsen`
370-
methods. This supports the block aggregation along multiple dimensions,
370+
methods. This supports block aggregation along multiple dimensions,
371371

372372
.. ipython:: python
373373
@@ -403,6 +403,7 @@ function or method name to ``coord_func`` option,
403403
404404
da.coarsen(time=7, x=2, coord_func={"time": "min"}).mean()
405405
406+
You can also :ref:`use coarsen to reshape<reshape.coarsen>` without applying a computation.
406407

407408
.. _compute.using_coordinates:
408409

doc/user-guide/plotting.rst

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,18 @@ Keyword arguments work the same way, and are more explicit.
156156

157157
To add the plot to an existing axis pass in the axis as a keyword argument
158158
``ax``. This works for all xarray plotting methods.
159-
In this example ``axes`` is an array consisting of the left and right
159+
In this example ``axs`` is an array consisting of the left and right
160160
axes created by ``plt.subplots``.
161161

162162
.. ipython:: python
163163
:okwarning:
164164
165-
fig, axes = plt.subplots(ncols=2)
165+
fig, axs = plt.subplots(ncols=2)
166166
167-
axes
167+
axs
168168
169-
air1d.plot(ax=axes[0])
170-
air1d.plot.hist(ax=axes[1])
169+
air1d.plot(ax=axs[0])
170+
air1d.plot.hist(ax=axs[1])
171171
172172
plt.tight_layout()
173173
@@ -348,8 +348,8 @@ The keyword arguments ``xincrease`` and ``yincrease`` let you control the axes d
348348
349349
In addition, one can use ``xscale, yscale`` to set axes scaling;
350350
``xticks, yticks`` to set axes ticks and ``xlim, ylim`` to set axes limits.
351-
These accept the same values as the matplotlib methods ``Axes.set_(x,y)scale()``,
352-
``Axes.set_(x,y)ticks()``, ``Axes.set_(x,y)lim()`` respectively.
351+
These accept the same values as the matplotlib methods ``ax.set_(x,y)scale()``,
352+
``ax.set_(x,y)ticks()``, ``ax.set_(x,y)lim()``, respectively.
353353

354354

355355
Two Dimensions
@@ -701,12 +701,12 @@ that links a :py:class:`DataArray` to a matplotlib figure with a particular stru
701701
This object can be used to control the behavior of the multiple plots.
702702
It borrows an API and code from `Seaborn's FacetGrid
703703
<https://seaborn.pydata.org/tutorial/axis_grids.html>`_.
704-
The structure is contained within the ``axes`` and ``name_dicts``
704+
The structure is contained within the ``axs`` and ``name_dicts``
705705
attributes, both 2d NumPy object arrays.
706706

707707
.. ipython:: python
708708
709-
g.axes
709+
g.axs
710710
711711
g.name_dicts
712712
@@ -726,10 +726,10 @@ they have been plotted.
726726
727727
g = t.plot.imshow(x="lon", y="lat", col="time", col_wrap=3, robust=True)
728728
729-
for i, ax in enumerate(g.axes.flat):
729+
for i, ax in enumerate(g.axs.flat):
730730
ax.set_title("Air Temperature %d" % i)
731731
732-
bottomright = g.axes[-1, -1]
732+
bottomright = g.axs[-1, -1]
733733
bottomright.annotate("bottom right", (240, 40))
734734
735735
@savefig plot_facet_iterator.png
@@ -928,7 +928,7 @@ by faceting are accessible in the object returned by ``plot``:
928928
col="time",
929929
subplot_kws={"projection": ccrs.Orthographic(-80, 35)},
930930
)
931-
for ax in p.axes.flat:
931+
for ax in p.axs.flat:
932932
ax.coastlines()
933933
ax.gridlines()
934934
@savefig plotting_maps_cartopy_facetting.png width=100%
@@ -958,11 +958,11 @@ These are provided for user convenience; they all call the same code.
958958
import xarray.plot as xplt
959959
960960
da = xr.DataArray(range(5))
961-
fig, axes = plt.subplots(ncols=2, nrows=2)
962-
da.plot(ax=axes[0, 0])
963-
da.plot.line(ax=axes[0, 1])
964-
xplt.plot(da, ax=axes[1, 0])
965-
xplt.line(da, ax=axes[1, 1])
961+
fig, axs = plt.subplots(ncols=2, nrows=2)
962+
da.plot(ax=axs[0, 0])
963+
da.plot.line(ax=axs[0, 1])
964+
xplt.plot(da, ax=axs[1, 0])
965+
xplt.line(da, ax=axs[1, 1])
966966
plt.tight_layout()
967967
@savefig plotting_ways_to_use.png width=6in
968968
plt.draw()

doc/user-guide/reshaping.rst

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Reshaping and reorganizing data
55
###############################
66

7-
These methods allow you to reorganize
7+
These methods allow you to reorganize your data by changing dimensions, array shape, order of values, or indexes.
88

99
.. ipython:: python
1010
:suppress:
@@ -292,3 +292,54 @@ As a shortcut, you can refer to existing coordinates by name:
292292
ds.sortby("x")
293293
ds.sortby(["y", "x"])
294294
ds.sortby(["y", "x"], ascending=False)
295+
296+
.. _reshape.coarsen:
297+
298+
Reshaping via coarsen
299+
---------------------
300+
301+
Whilst :py:class:`~xarray.DataArray.coarsen` is normally used for reducing your data's resolution by applying a reduction function
302+
(see the :ref:`page on computation<compute.coarsen>`),
303+
it can also be used to reorganise your data without applying a computation via :py:meth:`~xarray.core.rolling.DataArrayCoarsen.construct`.
304+
305+
Taking our example tutorial air temperature dataset over the Northern US
306+
307+
.. ipython:: python
308+
:suppress:
309+
310+
# Use defaults so we don't get gridlines in generated docs
311+
import matplotlib as mpl
312+
313+
mpl.rcdefaults()
314+
315+
.. ipython:: python
316+
317+
air = xr.tutorial.open_dataset("air_temperature")["air"]
318+
319+
@savefig pre_coarsening.png
320+
air.isel(time=0).plot(x="lon", y="lat")
321+
322+
we can split this up into sub-regions of size ``(9, 18)`` points using :py:meth:`~xarray.core.rolling.DataArrayCoarsen.construct`:
323+
324+
.. ipython:: python
325+
326+
regions = air.coarsen(lat=9, lon=18, boundary="pad").construct(
327+
lon=("x_coarse", "x_fine"), lat=("y_coarse", "y_fine")
328+
)
329+
regions
330+
331+
9 new regions have been created, each of size 9 by 18 points.
332+
The ``boundary="pad"`` kwarg ensured that all regions are the same size even though the data does not evenly divide into these sizes.
333+
334+
By plotting these 9 regions together via :ref:`faceting<plotting.faceting>` we can see how they relate to the original data.
335+
336+
.. ipython:: python
337+
338+
@savefig post_coarsening.png
339+
regions.isel(time=0).plot(
340+
x="x_fine", y="y_fine", col="x_coarse", row="y_coarse", yincrease=False
341+
)
342+
343+
We are now free to easily apply any custom computation to each coarsened region of our new dataarray.
344+
This would involve specifying that applied functions should act over the ``"x_fine"`` and ``"y_fine"`` dimensions,
345+
but broadcast over the ``"x_coarse"`` and ``"y_coarse"`` dimensions.

doc/whats-new.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ New Features
2525

2626
- Add static typing to plot accessors (:issue:`6949`, :pull:`7052`).
2727
By `Michael Niklas <https://github.com/headtr1ck>`_.
28+
- Display the indexes in a new section of the text and HTML reprs
29+
(:pull:`6795`, :pull:`7183`, :pull:`7185`)
30+
By `Justus Magin <https://github.com/keewis>`_ and `Benoît Bovy <https://github.com/benbovy>`_.
2831

2932
Breaking changes
3033
~~~~~~~~~~~~~~~~
@@ -39,6 +42,10 @@ Deprecations
3942

4043
- Positional arguments for all plot methods have been deprecated (:issue:`6949`, :pull:`7052`).
4144
By `Michael Niklas <https://github.com/headtr1ck>`_.
45+
- ``xarray.plot.FacetGrid.axes`` has been renamed to ``xarray.plot.FacetGrid.axs``
46+
because it's not clear if ``axes`` refers to single or multiple ``Axes`` instances.
47+
This aligns with ``matplotlib.pyplot.subplots``. (:pull:`7194`)
48+
By `Jimmy Westling <https://github.com/illviljan>`_.
4249

4350
Bug fixes
4451
~~~~~~~~~
@@ -55,7 +62,10 @@ Documentation
5562
Add :py:meth:`__str__` to surface the new :py:class:`BackendEntrypoint` ``description``
5663
and ``url`` attributes. (:issue:`6577`, :pull:`7000`)
5764
By `Jessica Scheick <https://github.com/jessicas11>`_.
58-
65+
- Add example of using :py:meth:`DataArray.coarsen.construct` to User Guide. (:pull:`7192`)
66+
By `Tom Nicholas <https://github.com/TomNicholas>`_.
67+
- Rename ``axes`` to ``axs`` in plotting to align with ``matplotlib.pyplot.subplots``. (:pull:`7194`)
68+
By `Jimmy Westling <https://github.com/illviljan>`_.
5969

6070
Internal Changes
6171
~~~~~~~~~~~~~~~~
@@ -2992,7 +3002,7 @@ Highlights include:
29923002
- Removed support for Python 2. This is the first version of xarray that is
29933003
Python 3 only!
29943004
- New :py:meth:`~xarray.DataArray.coarsen` and
2995-
:py:meth:`~xarray.DataArray.integrate` methods. See :ref:`comput.coarsen`
3005+
:py:meth:`~xarray.DataArray.integrate` methods. See :ref:`compute.coarsen`
29963006
and :ref:`compute.using_coordinates` for details.
29973007
- Many improvements to cftime support. See below for details.
29983008

@@ -3048,7 +3058,7 @@ Other enhancements
30483058
By `Ryan Abernathey <https://github.com/rabernat>`_
30493059
- :py:meth:`DataArray.coarsen` and
30503060
:py:meth:`Dataset.coarsen` are newly added.
3051-
See :ref:`comput.coarsen` for details.
3061+
See :ref:`compute.coarsen` for details.
30523062
(:issue:`2525`)
30533063
By `Keisuke Fujii <https://github.com/fujiisoup>`_.
30543064
- Upsampling an array via interpolation with resample is now dask-compatible,

0 commit comments

Comments
 (0)