Skip to content

Commit 851b77b

Browse files
authored
MAINT: bump Python, make tests robust to tile changes (#264)
* bump python * test robust to tile changes * update expected value * another one
1 parent 50ff0da commit 851b77b

5 files changed

Lines changed: 32 additions & 24 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ jobs:
2020
matrix:
2121
os: [ubuntu-latest]
2222
environment-file:
23-
- ci/envs/39-minimal.yaml
2423
- ci/envs/310-conda-forge.yaml
2524
- ci/envs/311-conda-forge.yaml
2625
- ci/envs/312-latest-conda-forge.yaml
26+
- ci/envs/313-latest-conda-forge.yaml
2727
include:
2828
- os: macos-13
29-
environment-file: ci/envs/312-latest-conda-forge.yaml
29+
environment-file: ci/envs/313-latest-conda-forge.yaml
3030
- os: macos-latest # apple silicon
31-
environment-file: ci/envs/312-latest-conda-forge.yaml
31+
environment-file: ci/envs/313-latest-conda-forge.yaml
3232
- os: windows-latest
33-
environment-file: ci/envs/312-latest-conda-forge.yaml
33+
environment-file: ci/envs/313-latest-conda-forge.yaml
3434
defaults:
3535
run:
3636
shell: bash -l {0}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `contextily`: context geo tiles in Python
22

3-
`contextily` is a small Python 3 (3.9 and above) package to retrieve tile maps from the
3+
`contextily` is a small Python 3 (3.10 and above) package to retrieve tile maps from the
44
internet. It can add those tiles as basemap to matplotlib figures or write tile
55
maps to disk into geospatial raster files. Bounding boxes can be passed in both
66
WGS84 (`EPSG:4326`) and Spheric Mercator (`EPSG:3857`). See the notebook
@@ -33,7 +33,7 @@ package. This includes some popular tile maps, such as:
3333

3434
## Installation
3535

36-
**Python 3 only** (3.9 and above)
36+
**Python 3 only** (3.10 and above)
3737

3838
[Latest released version](https://github.com/geopandas/contextily/releases/), using pip:
3939

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: test-environment
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=3.9
5+
- python=3.13
66
# required
77
- geopy
88
- matplotlib
@@ -15,4 +15,4 @@ dependencies:
1515
# testing
1616
- pip
1717
- pytest
18-
- pytest-cov
18+
- pytest-cov

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ readme = "README.md"
1919
classifiers = [
2020
"License :: OSI Approved :: BSD License",
2121
"Programming Language :: Python :: 3",
22+
"Programming Language :: Python :: 3.10",
23+
"Programming Language :: Python :: 3.11",
24+
"Programming Language :: Python :: 3.12",
25+
"Programming Language :: Python :: 3.13",
2226
"Framework :: Matplotlib",
2327
]
24-
requires-python = ">=3.9"
28+
requires-python = ">=3.10"
2529
dependencies = [
2630
"geopy",
2731
"matplotlib",

tests/test_cx.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ def test_bounds2raster():
3939
)
4040
for i, j in zip(rtr.bounds, solu):
4141
assert round(i - j, TOL) == 0
42-
assert img[0, 100, :].tolist() == [250, 250, 248, 255]
43-
assert img[20, 120, :].tolist() == [139, 153, 164, 255]
44-
assert img[200, 100, :].tolist() == [250, 250, 248, 255]
42+
# Check approximate pixel values instead of exact matches for robustness
43+
assert np.allclose(img[0, 100, :], [250, 250, 248, 255], atol=10)
44+
assert np.allclose(img[20, 120, :], [139, 153, 164, 255], atol=10)
45+
assert np.allclose(img[200, 100, :], [250, 250, 248, 255], atol=10)
4546
assert img[:, :, :3].sum() == pytest.approx(47622796, rel=0.1)
4647
assert img.sum() == pytest.approx(64334476, rel=0.1)
4748
assert_array_almost_equal(img[:, :, :3].mean(), 242.2220662434896, decimal=0)
@@ -105,9 +106,10 @@ def test_bounds2img(n_connections):
105106
)
106107
for i, j in zip(ext, solu):
107108
assert round(i - j, TOL) == 0
108-
assert img[0, 100, :].tolist() == [250, 250, 248, 255]
109-
assert img[20, 120, :].tolist() == [139, 153, 164, 255]
110-
assert img[200, 100, :].tolist() == [250, 250, 248, 255]
109+
# Check approximate pixel values instead of exact matches for robustness
110+
assert np.allclose(img[0, 100, :], [250, 250, 248, 255], atol=10)
111+
assert np.allclose(img[20, 120, :], [139, 153, 164, 255], atol=10)
112+
assert np.allclose(img[200, 100, :], [250, 250, 248, 255], atol=10)
111113
elif n_connections == 0: # no connections should raise an error
112114
with pytest.raises(ValueError):
113115
img, ext = cx.bounds2img(
@@ -138,9 +140,10 @@ def test_warp_tiles():
138140
]
139141
),
140142
)
141-
assert wimg[100, 100, :].tolist() == [249, 249, 247, 255]
142-
assert wimg[100, 200, :].tolist() == [250, 250, 248, 255]
143-
assert wimg[20, 120, :].tolist() == [250, 250, 248, 255]
143+
# Check approximate pixel values instead of exact matches for robustness
144+
assert np.allclose(wimg[100, 100, :], [249, 249, 247, 255], atol=10)
145+
assert np.allclose(wimg[100, 200, :], [250, 250, 248, 255], atol=10)
146+
assert np.allclose(wimg[20, 120, :], [250, 250, 248, 255], atol=10)
144147

145148

146149
@pytest.mark.network
@@ -157,9 +160,10 @@ def test_warp_img_transform():
157160
rtr = rio.open("test.tif")
158161
img = np.array([band for band in rtr.read()])
159162
wimg, _ = cx.warp_img_transform(img, rtr.transform, rtr.crs, "epsg:4326")
160-
assert wimg[:, 100, 100].tolist() == [249, 249, 247, 255]
161-
assert wimg[:, 100, 200].tolist() == [250, 250, 248, 255]
162-
assert wimg[:, 20, 120].tolist() == [250, 250, 248, 255]
163+
# Check approximate pixel values instead of exact matches for robustness
164+
assert np.allclose(wimg[:, 100, 100], [249, 249, 247, 255], atol=10)
165+
assert np.allclose(wimg[:, 100, 200], [250, 250, 248, 255], atol=10)
166+
assert np.allclose(wimg[:, 20, 120], [250, 250, 248, 255], atol=10)
163167

164168

165169
def test_howmany():
@@ -369,7 +373,7 @@ def test_add_basemap_query():
369373
ax_extent = (x1, x2, y1, y2)
370374
assert ax.axis() == ax_extent
371375

372-
assert ax.images[0].get_array().sum() == 64685390
376+
assert ax.images[0].get_array().sum() == pytest.approx(64685390, rel=0.1)
373377
assert ax.images[0].get_array().shape == (256, 256, 4)
374378
assert_array_almost_equal(
375379
ax.images[0].get_array()[:, :, :3].mean(), 244.03656, decimal=0
@@ -451,8 +455,8 @@ def test_add_basemap_auto_zoom():
451455
4852834.0517692715,
452456
4891969.810251278,
453457
),
454-
763769618,
455-
1031156498,
458+
764077703,
459+
1031464583,
456460
(1024, 1024, 4),
457461
),
458462
# zoom_adjust and expected values where zoom_adjust == -1

0 commit comments

Comments
 (0)