Skip to content

Commit b18680a

Browse files
authored
Merge pull request OSGeo#11873 from rouault/fix_11853
Python bindings: honour GDAL_PYTHON_BINDINGS_WITHOUT_NUMPY=YES/1/ON/TRUE or NO/0/OFF/FALSE
2 parents c94c42e + 6378b44 commit b18680a

27 files changed

+117
-88
lines changed

autotest/alg/sieve.py

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def test_sieve_5():
176176

177177
def test_sieve_6():
178178

179+
pytest.importorskip("osgeo.gdal_array")
179180
numpy = pytest.importorskip("numpy")
180181

181182
# Try 3002. Should run in less than 10 seconds

autotest/alg/transformgeoloc.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
def test_transformgeoloc_1():
2626

27+
pytest.importorskip("osgeo.gdal_array")
2728
numpy = pytest.importorskip("numpy")
2829

2930
# Setup 2x2 geolocation arrays in a memory dataset with lat/long values.

autotest/alg/warp.py

+4
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ def test_warp_weighted_average():
11751175
)
11761176
def test_warp_weighted_mode(dtype):
11771177

1178+
pytest.importorskip("osgeo.gdal_array")
11781179
np = pytest.importorskip("numpy")
11791180

11801181
with gdal.GetDriverByName("MEM").Create("", 3, 3, eType=dtype) as src_ds:
@@ -1563,6 +1564,7 @@ def test_warp_55():
15631564
@pytest.mark.parametrize("use_optim", ["YES", "NO"])
15641565
def test_warp_56(use_optim):
15651566

1567+
pytest.importorskip("osgeo.gdal_array")
15661568
numpy = pytest.importorskip("numpy")
15671569

15681570
pix_ds = gdal.GetDriverByName("MEM").Create("", 1, 1)
@@ -1660,6 +1662,8 @@ def test_warp_rms_2():
16601662
@pytest.mark.parametrize("tie_strategy", ("FIRST", "MIN", "MAX", "HOPE"))
16611663
@pytest.mark.parametrize("dtype", (gdal.GDT_Int16, gdal.GDT_Int32))
16621664
def test_warp_mode_ties(tie_strategy, dtype):
1665+
1666+
pytest.importorskip("osgeo.gdal_array")
16631667
numpy = pytest.importorskip("numpy")
16641668

16651669
# 1 and 5 are tied for the mode; 1 encountered first

autotest/gcore/hfa_rfc40.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
# All tests will be skipped if numpy is unavailable.
2626
np = pytest.importorskip("numpy")
27-
27+
pytest.importorskip("osgeo.gdal_array")
2828

2929
INT_DATA = np.array([197, 83, 46, 29, 1, 78, 23, 90, 12, 45])
3030
DOUBLE_DATA = np.array([0.1, 43.2, 78.1, 9.9, 23.0, 0.92, 82.5, 0.0, 1.0, 99.0])

autotest/gcore/interpolateatpoint.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ def test_interpolateatpoint_throw():
6868

6969
def test_interpolateatpoint_2_bands():
7070

71+
pytest.importorskip("osgeo.gdal_array")
72+
np = pytest.importorskip("numpy")
73+
7174
mem_ds = gdal.GetDriverByName("MEM").Create(
7275
"", xsize=2, ysize=2, bands=2, eType=gdal.GDT_Float32
7376
)
74-
np = pytest.importorskip("numpy")
77+
7578
# First band with values values
7679
raster_array_1 = np.array(([10.5, 1.3], [2.4, 3.8]))
7780
mem_ds.GetRasterBand(1).WriteArray(raster_array_1)
@@ -94,10 +97,12 @@ def test_interpolateatpoint_2_bands():
9497

9598
def test_interpolateatpoint_bilinear_several_points():
9699

100+
pytest.importorskip("osgeo.gdal_array")
101+
np = pytest.importorskip("numpy")
102+
97103
mem_ds = gdal.GetDriverByName("MEM").Create(
98104
"", xsize=3, ysize=2, bands=1, eType=gdal.GDT_Float32
99105
)
100-
np = pytest.importorskip("numpy")
101106
raster_array_1 = np.array(([10.5, 1.3, 0.5], [2.4, 3.8, -1.0]))
102107
mem_ds.GetRasterBand(1).WriteArray(raster_array_1)
103108

@@ -131,10 +136,12 @@ def test_interpolateatpoint_bilinear_several_points():
131136

132137
def test_interpolateatpoint_cubicspline_several_points():
133138

139+
pytest.importorskip("osgeo.gdal_array")
140+
np = pytest.importorskip("numpy")
141+
134142
mem_ds = gdal.GetDriverByName("MEM").Create(
135143
"", xsize=4, ysize=4, bands=1, eType=gdal.GDT_Float32
136144
)
137-
np = pytest.importorskip("numpy")
138145
raster_array_1 = np.array(
139146
(
140147
[1.0, 2.0, 1.5, -0.3],
@@ -160,10 +167,12 @@ def test_interpolateatpoint_cubicspline_several_points():
160167

161168
def test_interpolateatpoint_cubic_several_points():
162169

170+
pytest.importorskip("osgeo.gdal_array")
171+
np = pytest.importorskip("numpy")
172+
163173
mem_ds = gdal.GetDriverByName("MEM").Create(
164174
"", xsize=4, ysize=4, bands=1, eType=gdal.GDT_Float32
165175
)
166-
np = pytest.importorskip("numpy")
167176
raster_array_1 = np.array(
168177
(
169178
[1.0, 2.0, 1.5, -0.3],
@@ -196,10 +205,12 @@ def test_interpolateatpoint_cubic_several_points():
196205

197206
def test_interpolateatpoint_at_borders():
198207

208+
pytest.importorskip("osgeo.gdal_array")
209+
np = pytest.importorskip("numpy")
210+
199211
mem_ds = gdal.GetDriverByName("MEM").Create(
200212
"", xsize=6, ysize=5, bands=1, eType=gdal.GDT_Float32
201213
)
202-
np = pytest.importorskip("numpy")
203214
raster_array_1 = np.array(
204215
(
205216
[1, 2, 4, 4, 5, 6],

autotest/gcore/pixfun.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# All tests will be skipped if numpy is unavailable.
2727
numpy = pytest.importorskip("numpy")
28-
28+
pytest.importorskip("osgeo.gdal_array")
2929

3030
###############################################################################
3131
# Verify real part extraction from a complex dataset.

autotest/gcore/rasterio.py

+15
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ def test_rasterio_9():
709709

710710
def test_rasterio_overview_subpixel_resampling():
711711

712+
pytest.importorskip("osgeo.gdal_array")
712713
numpy = pytest.importorskip("numpy")
713714

714715
temp_path = "/vsimem/rasterio_ovr.tif"
@@ -774,6 +775,8 @@ def test_rasterio_10():
774775

775776

776777
def test_rasterio_11():
778+
779+
pytest.importorskip("osgeo.gdal_array")
777780
numpy = pytest.importorskip("numpy")
778781

779782
mem_ds = gdal.GetDriverByName("MEM").Create("", 4, 3)
@@ -810,6 +813,8 @@ def rasterio_12_progress_callback(pct, message, user_data):
810813

811814

812815
def test_rasterio_12():
816+
817+
pytest.importorskip("osgeo.gdal_array")
813818
numpy = pytest.importorskip("numpy")
814819

815820
mem_ds = gdal.GetDriverByName("MEM").Create("", 4, 3, 4)
@@ -878,6 +883,8 @@ def test_rasterio_12():
878883
],
879884
)
880885
def test_rasterio_13(dt):
886+
887+
pytest.importorskip("osgeo.gdal_array")
881888
numpy = pytest.importorskip("numpy")
882889

883890
dt = gdal.GetDataTypeByName(dt)
@@ -1206,6 +1213,8 @@ def test_rasterio_16():
12061213

12071214

12081215
def test_rasterio_nodata():
1216+
1217+
pytest.importorskip("osgeo.gdal_array")
12091218
pytest.importorskip("numpy")
12101219

12111220
ndv = 123
@@ -1413,6 +1422,8 @@ def test_rasterio_resampled_value_is_nodata():
14131422

14141423

14151424
def test_rasterio_dataset_readarray_cint16():
1425+
1426+
pytest.importorskip("osgeo.gdal_array")
14161427
numpy = pytest.importorskip("numpy")
14171428

14181429
mem_ds = gdal.GetDriverByName("MEM").Create("", 1, 1, 2, gdal.GDT_CInt16)
@@ -1488,6 +1499,8 @@ def test_rasterio_floating_point_window_no_resampling():
14881499

14891500
def test_rasterio_floating_point_window_no_resampling_numpy():
14901501
# Same as above but using ReadAsArray() instead of ReadRaster()
1502+
1503+
pytest.importorskip("osgeo.gdal_array")
14911504
numpy = pytest.importorskip("numpy")
14921505

14931506
ds = gdal.Translate(
@@ -3158,6 +3171,8 @@ def test_rasterio_gdal_rasterio_resampling():
31583171

31593172

31603173
def test_rasterio_numpy_datatypes_for_xoff():
3174+
3175+
pytest.importorskip("osgeo.gdal_array")
31613176
np = pytest.importorskip("numpy")
31623177

31633178
ds = gdal.Open("data/byte.tif")

autotest/gcore/tiff_ovr.py

+1
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,7 @@ def test_tiff_ovr_color_table_bug_3336_bis():
24722472

24732473
def test_tiff_ovr_nodata_multiband():
24742474

2475+
pytest.importorskip("osgeo.gdal_array")
24752476
numpy = pytest.importorskip("numpy")
24762477

24772478
temp_path = "/vsimem/test.tif"

autotest/gcore/tiff_write.py

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def test_tiff_write_3():
149149

150150
def test_tiff_write_4():
151151

152+
pytest.importorskip("osgeo.gdal_array")
152153
np = pytest.importorskip("numpy")
153154

154155
options = ["TILED=YES", "BLOCKXSIZE=32", "BLOCKYSIZE=32"]

autotest/gcore/virtualmem.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
from osgeo import gdal
2020

2121
# All tests will be skipped if numpy unavailable or SKIP_VIRTUALMEM is set.
22+
pytest.importorskip("osgeo.gdal_array")
2223
numpy = pytest.importorskip("numpy")
24+
2325
pytestmark = pytest.mark.skipif(
2426
gdal.GetConfigOption("SKIP_VIRTUALMEM"), reason="SKIP_VIRTUALMEM is set in config"
2527
)

autotest/gcore/vrt_read.py

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def test_vrt_read_3():
128128

129129
def test_vrt_read_4():
130130

131+
pytest.importorskip("osgeo.gdal_array")
131132
np = pytest.importorskip("numpy")
132133

133134
data = np.zeros((1, 1), np.complex64)
@@ -961,6 +962,7 @@ def test_vrt_read_22():
961962

962963
def test_vrt_read_23():
963964

965+
pytest.importorskip("osgeo.gdal_array")
964966
numpy = pytest.importorskip("numpy")
965967

966968
mem_ds = gdal.GetDriverByName("GTiff").Create("/vsimem/vrt_read_23.tif", 2, 1)

autotest/gdrivers/lcp.py

+2
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,8 @@ def test_lcp_21():
849849

850850

851851
def test_lcp_22():
852+
853+
pytest.importorskip("osgeo.gdal_array")
852854
numpy = pytest.importorskip("numpy")
853855

854856
mem_drv = gdal.GetDriverByName("MEM")

autotest/gdrivers/memmultidim.py

+4
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,10 @@ def test_mem_md_array_get_mask():
20382038
try:
20392039
import numpy
20402040

2041+
from osgeo import gdal_array
2042+
2043+
str(gdal_array)
2044+
20412045
has_numpy = True
20422046
except ImportError:
20432047
has_numpy = False

autotest/gdrivers/netcdf.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2920,10 +2920,8 @@ def test_netcdf_66(tmp_path):
29202920

29212921
def test_netcdf_67():
29222922

2923-
try:
2924-
import numpy
2925-
except ImportError:
2926-
pytest.skip()
2923+
pytest.importorskip("osgeo.gdal_array")
2924+
numpy = pytest.importorskip("numpy")
29272925

29282926
# disable bottom-up mode to use the real file's blocks size
29292927
with gdal.config_option("GDAL_NETCDF_BOTTOMUP", "NO"):

autotest/gdrivers/rmf.py

+4
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ def rmf_31e_data_gen(min_val, max_val, stripeSize, sx):
702702

703703

704704
def test_rmf_31e():
705+
706+
pytest.importorskip("osgeo.gdal_array")
705707
numpy = pytest.importorskip("numpy")
706708

707709
drv = gdal.GetDriverByName("Gtiff")
@@ -846,6 +848,8 @@ def test_rmf_33c():
846848

847849

848850
def test_rmf_34():
851+
852+
pytest.importorskip("osgeo.gdal_array")
849853
numpy = pytest.importorskip("numpy")
850854

851855
drv = gdal.GetDriverByName("RMF")

autotest/gdrivers/tiledb_write.py

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def test_tiledb_write_custom_blocksize(tmp_path, mode):
7373

7474
@pytest.mark.parametrize("mode", ["BAND", "PIXEL"])
7575
def test_tiledb_write_update(tmp_path, mode):
76+
77+
pytest.importorskip("osgeo.gdal_array")
7678
np = pytest.importorskip("numpy")
7779

7880
gdaltest.tiledb_drv = gdal.GetDriverByName("TileDB")
@@ -240,6 +242,8 @@ def test_tiledb_write_band_meta(tmp_path, mode):
240242

241243
@pytest.mark.parametrize("mode", ["BAND", "PIXEL"])
242244
def test_tiledb_write_history(tmp_path, mode):
245+
246+
pytest.importorskip("osgeo.gdal_array")
243247
np = pytest.importorskip("numpy")
244248

245249
options = ["INTERLEAVE=%s" % (mode), "TILEDB_TIMESTAMP=1"]

0 commit comments

Comments
 (0)