Skip to content

Commit 52068a6

Browse files
authored
CI: test upstream dev (#133)
* CI: test upstream dev * remove timeout * avoid unwritable array * use variable * changelog
1 parent 05843ab commit 52068a6

File tree

5 files changed

+121
-9
lines changed

5 files changed

+121
-9
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: CI Upstream
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
types: [opened, reopened, synchronize, labeled]
10+
schedule:
11+
- cron: "0 0 * * *" # Daily “At 00:00” UTC
12+
# TODO: switch to weekly once I know this works
13+
# - cron: "0 17 * * 1" # “At 17:00 on Monday” UTC
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
21+
upstream-dev:
22+
name: upstream-dev
23+
runs-on: ubuntu-latest
24+
if: |
25+
always()
26+
&& (
27+
github.event_name == 'schedule'
28+
|| contains( github.event.pull_request.labels.*.name, 'run-upstream')
29+
)
30+
defaults:
31+
run:
32+
shell: bash -l {0}
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
python-version: ["3.12"]
37+
steps:
38+
- uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0 # Fetch all history for all branches and tags.
41+
- name: Set up conda environment
42+
uses: mamba-org/setup-micromamba@v2
43+
with:
44+
environment-file: ci/requirements/environment.yml
45+
environment-name: mplotutils-tests
46+
create-args: >-
47+
python=${{ matrix.python-version }}
48+
pytest-reportlog
49+
conda
50+
- name: Install upstream versions
51+
run: |
52+
bash ci/install-upstream-wheels.sh
53+
- name: Install mplotutils
54+
run: |
55+
python -m pip install --no-deps -e .
56+
- name: Version info
57+
run: |
58+
conda info -a
59+
conda list
60+
61+
- name: Import mplotutils
62+
run: |
63+
python -c 'import mplotutils'
64+
- name: Run Tests
65+
if: success()
66+
id: status
67+
run: |
68+
python -m pytest -rf \
69+
--report-log output-${{ matrix.python-version }}-log.jsonl
70+
- name: Generate and publish the report
71+
if: |
72+
failure()
73+
&& steps.status.outcome == 'failure'
74+
&& github.event_name == 'schedule'
75+
&& github.repository_owner == 'regionmask'
76+
uses: xarray-contrib/issue-from-pytest-log@v1
77+
with:
78+
log-path: output-${{ matrix.python-version }}-log.jsonl

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
### Enhancements
1919

20-
- Added convinience functions to draw hatches and add stippling:
20+
- Added convenience functions to draw hatches and add stippling:
2121

2222
1. `mpu.hatch`: for regular axes
2323
2. `mpu.hatch_map`: for cartopy GeoAxes
@@ -28,6 +28,7 @@
2828
- Enable passing `AxesGrid` (from `mpl_toolkits.axes_grid1`) to `set_map_layout` ([#116](https://github.com/mathause/mplotutils/pull/116)).
2929
- Raise more informative error when a wrong type is passed to `set_map_layout` ([#121](https://github.com/mathause/mplotutils/pull/121)).
3030
- `set_map_layout` now raises an explicit error when the figure contains SubFigure ([#121](https://github.com/mathause/mplotutils/pull/121)).
31+
- Test upstream dependencies and fix compatibility with the upcoming pandas v3 ([#133](https://github.com/mathause/mplotutils/pull/133)).
3132

3233
## v0.5.0 (27.03.2024)
3334

ci/install-upstream-wheels.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# forcibly remove packages to avoid artifacts
4+
conda uninstall -y --force \
5+
cartopy \
6+
matplotlib-base \
7+
numpy \
8+
packaging \
9+
pandas \
10+
xarray
11+
# to limit the runtime of Upstream CI
12+
python -m pip install \
13+
-i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
14+
--no-deps \
15+
--pre \
16+
--upgrade \
17+
matplotlib \
18+
numpy \
19+
pandas \
20+
shapely \
21+
xarray
22+
python -m pip install \
23+
--no-deps \
24+
--upgrade \
25+
git+https://github.com/mwaskom/seaborn \
26+
git+https://github.com/pypa/packaging \
27+
git+https://github.com/SciTools/cartopy

mplotutils/cartopy_utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,18 @@ def cyclic_dataarray(obj, coord="lon"):
118118
obj = obj.pad({coord: (0, 1)}, mode="wrap")
119119

120120
# extrapolate the coords
121-
lon = obj[coord]
122-
123-
diff = lon.isel({coord: slice(None, -1)}).diff(coord)
121+
diff = obj[coord].isel({coord: slice(None, -1)}).diff(coord)
124122

125123
if not np.allclose(diff, diff[0]):
126124
raise ValueError(f"The coordinate '{coord}' must be equally spaced")
127125

128-
lon.data[-1] = lon[-2] + diff[0]
126+
# the data is not writable (pandas 3) - a copy is required
127+
lon = obj[coord].variable
128+
129+
arr = np.array(lon.data)
130+
arr[-1] = arr[-2] + diff[0]
131+
132+
lon = type(lon)(lon.dims, arr, attrs=lon.attrs, encoding=lon.encoding)
129133

130134
return obj.assign_coords({coord: lon})
131135

mplotutils/tests/test_cyclic_dataarray.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ def test_cyclic_dataarray_not_equally_spaced(as_dataset):
2828
@pytest.mark.parametrize("as_dataset", (True, False))
2929
def test_cyclic_dataarray(as_dataset):
3030
data = [[1, 2, 3], [4, 5, 6]]
31-
da = xr.DataArray(
32-
data, dims=("y", "x"), coords={"y": [1, 2], "x": [0, 1, 2]}, name="data"
33-
)
31+
32+
y = xr.Variable("y", [1, 2], attrs={"foo": "bar"})
33+
x = xr.Variable("x", [0, 1, 2], attrs={"foo": "bar"})
34+
da = xr.DataArray(data, dims=("y", "x"), coords={"y": y, "x": x}, name="data")
3435

3536
expected = [[1, 2, 3, 1], [4, 5, 6, 4]]
37+
x = xr.Variable("x", [0, 1, 2, 3], attrs={"foo": "bar"})
3638
da_expected = xr.DataArray(
37-
expected, dims=("y", "x"), coords={"y": [1, 2], "x": [0, 1, 2, 3]}, name="data"
39+
expected, dims=("y", "x"), coords={"y": y, "x": x}, name="data"
3840
)
3941

4042
data = da.to_dataset() if as_dataset else da

0 commit comments

Comments
 (0)