Skip to content

Commit

Permalink
Merge pull request OSGeo#11873 from rouault/fix_11853
Browse files Browse the repository at this point in the history
Python bindings: honour GDAL_PYTHON_BINDINGS_WITHOUT_NUMPY=YES/1/ON/TRUE or NO/0/OFF/FALSE
  • Loading branch information
rouault authored Mar 2, 2025
2 parents c94c42e + 6378b44 commit b18680a
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 88 deletions.
1 change: 1 addition & 0 deletions autotest/alg/sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def test_sieve_5():

def test_sieve_6():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

# Try 3002. Should run in less than 10 seconds
Expand Down
1 change: 1 addition & 0 deletions autotest/alg/transformgeoloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

def test_transformgeoloc_1():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

# Setup 2x2 geolocation arrays in a memory dataset with lat/long values.
Expand Down
4 changes: 4 additions & 0 deletions autotest/alg/warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@ def test_warp_weighted_average():
)
def test_warp_weighted_mode(dtype):

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

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

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

pix_ds = gdal.GetDriverByName("MEM").Create("", 1, 1)
Expand Down Expand Up @@ -1660,6 +1662,8 @@ def test_warp_rms_2():
@pytest.mark.parametrize("tie_strategy", ("FIRST", "MIN", "MAX", "HOPE"))
@pytest.mark.parametrize("dtype", (gdal.GDT_Int16, gdal.GDT_Int32))
def test_warp_mode_ties(tie_strategy, dtype):

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

# 1 and 5 are tied for the mode; 1 encountered first
Expand Down
2 changes: 1 addition & 1 deletion autotest/gcore/hfa_rfc40.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# All tests will be skipped if numpy is unavailable.
np = pytest.importorskip("numpy")

pytest.importorskip("osgeo.gdal_array")

INT_DATA = np.array([197, 83, 46, 29, 1, 78, 23, 90, 12, 45])
DOUBLE_DATA = np.array([0.1, 43.2, 78.1, 9.9, 23.0, 0.92, 82.5, 0.0, 1.0, 99.0])
Expand Down
21 changes: 16 additions & 5 deletions autotest/gcore/interpolateatpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ def test_interpolateatpoint_throw():

def test_interpolateatpoint_2_bands():

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

mem_ds = gdal.GetDriverByName("MEM").Create(
"", xsize=2, ysize=2, bands=2, eType=gdal.GDT_Float32
)
np = pytest.importorskip("numpy")

# First band with values values
raster_array_1 = np.array(([10.5, 1.3], [2.4, 3.8]))
mem_ds.GetRasterBand(1).WriteArray(raster_array_1)
Expand All @@ -94,10 +97,12 @@ def test_interpolateatpoint_2_bands():

def test_interpolateatpoint_bilinear_several_points():

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

mem_ds = gdal.GetDriverByName("MEM").Create(
"", xsize=3, ysize=2, bands=1, eType=gdal.GDT_Float32
)
np = pytest.importorskip("numpy")
raster_array_1 = np.array(([10.5, 1.3, 0.5], [2.4, 3.8, -1.0]))
mem_ds.GetRasterBand(1).WriteArray(raster_array_1)

Expand Down Expand Up @@ -131,10 +136,12 @@ def test_interpolateatpoint_bilinear_several_points():

def test_interpolateatpoint_cubicspline_several_points():

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

mem_ds = gdal.GetDriverByName("MEM").Create(
"", xsize=4, ysize=4, bands=1, eType=gdal.GDT_Float32
)
np = pytest.importorskip("numpy")
raster_array_1 = np.array(
(
[1.0, 2.0, 1.5, -0.3],
Expand All @@ -160,10 +167,12 @@ def test_interpolateatpoint_cubicspline_several_points():

def test_interpolateatpoint_cubic_several_points():

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

mem_ds = gdal.GetDriverByName("MEM").Create(
"", xsize=4, ysize=4, bands=1, eType=gdal.GDT_Float32
)
np = pytest.importorskip("numpy")
raster_array_1 = np.array(
(
[1.0, 2.0, 1.5, -0.3],
Expand Down Expand Up @@ -196,10 +205,12 @@ def test_interpolateatpoint_cubic_several_points():

def test_interpolateatpoint_at_borders():

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

mem_ds = gdal.GetDriverByName("MEM").Create(
"", xsize=6, ysize=5, bands=1, eType=gdal.GDT_Float32
)
np = pytest.importorskip("numpy")
raster_array_1 = np.array(
(
[1, 2, 4, 4, 5, 6],
Expand Down
2 changes: 1 addition & 1 deletion autotest/gcore/pixfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# All tests will be skipped if numpy is unavailable.
numpy = pytest.importorskip("numpy")

pytest.importorskip("osgeo.gdal_array")

###############################################################################
# Verify real part extraction from a complex dataset.
Expand Down
15 changes: 15 additions & 0 deletions autotest/gcore/rasterio.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ def test_rasterio_9():

def test_rasterio_overview_subpixel_resampling():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

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


def test_rasterio_11():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

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


def test_rasterio_12():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

mem_ds = gdal.GetDriverByName("MEM").Create("", 4, 3, 4)
Expand Down Expand Up @@ -878,6 +883,8 @@ def test_rasterio_12():
],
)
def test_rasterio_13(dt):

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

dt = gdal.GetDataTypeByName(dt)
Expand Down Expand Up @@ -1206,6 +1213,8 @@ def test_rasterio_16():


def test_rasterio_nodata():

pytest.importorskip("osgeo.gdal_array")
pytest.importorskip("numpy")

ndv = 123
Expand Down Expand Up @@ -1413,6 +1422,8 @@ def test_rasterio_resampled_value_is_nodata():


def test_rasterio_dataset_readarray_cint16():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

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

def test_rasterio_floating_point_window_no_resampling_numpy():
# Same as above but using ReadAsArray() instead of ReadRaster()

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

ds = gdal.Translate(
Expand Down Expand Up @@ -3158,6 +3171,8 @@ def test_rasterio_gdal_rasterio_resampling():


def test_rasterio_numpy_datatypes_for_xoff():

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

ds = gdal.Open("data/byte.tif")
Expand Down
1 change: 1 addition & 0 deletions autotest/gcore/tiff_ovr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,7 @@ def test_tiff_ovr_color_table_bug_3336_bis():

def test_tiff_ovr_nodata_multiband():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

temp_path = "/vsimem/test.tif"
Expand Down
1 change: 1 addition & 0 deletions autotest/gcore/tiff_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_tiff_write_3():

def test_tiff_write_4():

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

options = ["TILED=YES", "BLOCKXSIZE=32", "BLOCKYSIZE=32"]
Expand Down
2 changes: 2 additions & 0 deletions autotest/gcore/virtualmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
from osgeo import gdal

# All tests will be skipped if numpy unavailable or SKIP_VIRTUALMEM is set.
pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

pytestmark = pytest.mark.skipif(
gdal.GetConfigOption("SKIP_VIRTUALMEM"), reason="SKIP_VIRTUALMEM is set in config"
)
Expand Down
2 changes: 2 additions & 0 deletions autotest/gcore/vrt_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_vrt_read_3():

def test_vrt_read_4():

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

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

def test_vrt_read_23():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

mem_ds = gdal.GetDriverByName("GTiff").Create("/vsimem/vrt_read_23.tif", 2, 1)
Expand Down
2 changes: 2 additions & 0 deletions autotest/gdrivers/lcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ def test_lcp_21():


def test_lcp_22():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

mem_drv = gdal.GetDriverByName("MEM")
Expand Down
4 changes: 4 additions & 0 deletions autotest/gdrivers/memmultidim.py
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,10 @@ def test_mem_md_array_get_mask():
try:
import numpy

from osgeo import gdal_array

str(gdal_array)

has_numpy = True
except ImportError:
has_numpy = False
Expand Down
6 changes: 2 additions & 4 deletions autotest/gdrivers/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2920,10 +2920,8 @@ def test_netcdf_66(tmp_path):

def test_netcdf_67():

try:
import numpy
except ImportError:
pytest.skip()
pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

# disable bottom-up mode to use the real file's blocks size
with gdal.config_option("GDAL_NETCDF_BOTTOMUP", "NO"):
Expand Down
4 changes: 4 additions & 0 deletions autotest/gdrivers/rmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ def rmf_31e_data_gen(min_val, max_val, stripeSize, sx):


def test_rmf_31e():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

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


def test_rmf_34():

pytest.importorskip("osgeo.gdal_array")
numpy = pytest.importorskip("numpy")

drv = gdal.GetDriverByName("RMF")
Expand Down
4 changes: 4 additions & 0 deletions autotest/gdrivers/tiledb_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def test_tiledb_write_custom_blocksize(tmp_path, mode):

@pytest.mark.parametrize("mode", ["BAND", "PIXEL"])
def test_tiledb_write_update(tmp_path, mode):

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

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

@pytest.mark.parametrize("mode", ["BAND", "PIXEL"])
def test_tiledb_write_history(tmp_path, mode):

pytest.importorskip("osgeo.gdal_array")
np = pytest.importorskip("numpy")

options = ["INTERLEAVE=%s" % (mode), "TILEDB_TIMESTAMP=1"]
Expand Down
Loading

0 comments on commit b18680a

Please sign in to comment.