diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 971bbee33..133277a0b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -84,6 +84,14 @@ jobs: echo "Collected dependencies:" cat requirements-full.txt + - name: Rename conda-forge packages + run: | + echo "Rename conda-forge packages in requirements-full.txt" + # Replace "build" for "python-build" + sed -s --in-place 's/^build$/python-build/' requirements-full.txt + echo "Renamed dependencies:" + cat requirements-full.txt + - name: Install requirements run: conda install --file requirements-full.txt python=$PYTHON -c conda-forge diff --git a/environment.yml b/environment.yml index 1244f2311..04e22883b 100644 --- a/environment.yml +++ b/environment.yml @@ -7,7 +7,7 @@ dependencies: - pip # Build - twine - - build + - python-build # Run - numpy - scipy diff --git a/verde/coordinates.py b/verde/coordinates.py index 9ca49955a..2e78d1cb5 100644 --- a/verde/coordinates.py +++ b/verde/coordinates.py @@ -71,7 +71,8 @@ def get_region(coordinates): -------- >>> coords = grid_coordinates((0, 1, -10, -6), shape=(10, 10)) - >>> print(get_region(coords)) + >>> region = get_region(coords) + >>> print(tuple(float(c) for c in region)) (0.0, 1.0, -10.0, -6.0) """ @@ -233,9 +234,6 @@ def line_coordinates( Examples -------- - >>> # Lower printing precision to shorten this example - >>> import numpy as np; np.set_printoptions(precision=2, suppress=True) - >>> values = line_coordinates(0, 5, spacing=2.5) >>> print(values.shape) (3,) @@ -362,8 +360,6 @@ def grid_coordinates( >>> east, north = grid_coordinates(region=(0, 5, 0, 10), shape=(5, 3)) >>> print(east.shape, north.shape) (5, 3) (5, 3) - >>> # Lower printing precision to shorten this example - >>> import numpy as np; np.set_printoptions(precision=1, suppress=True) >>> print(east) [[0. 2.5 5. ] [0. 2.5 5. ] @@ -485,8 +481,6 @@ def grid_coordinates( >>> east, north = grid_coordinates(region=(0, 5, 0, 10), spacing=2.5, ... pixel_register=True) - >>> # Raise the printing precision for this example - >>> np.set_printoptions(precision=2, suppress=True) >>> # Notice that the shape is 1 less than when pixel_register=False >>> print(east.shape, north.shape) (4, 2) (4, 2) diff --git a/verde/projections.py b/verde/projections.py index 3aad65bd3..e0715c3b8 100644 --- a/verde/projections.py +++ b/verde/projections.py @@ -43,7 +43,8 @@ def project_region(region, projection): >>> def projection(x, y): ... return (2*x, -1*y) - >>> project_region((3, 5, -9, -4), projection) + >>> region_proj = project_region((3, 5, -9, -4), projection) + >>> print(tuple(float(c) for c in region_proj)) (6.0, 10.0, 4.0, 9.0) """ diff --git a/verde/tests/test_coordinates.py b/verde/tests/test_coordinates.py index f7d7a7ef0..c2608064a 100644 --- a/verde/tests/test_coordinates.py +++ b/verde/tests/test_coordinates.py @@ -75,28 +75,23 @@ def test_rolling_window_no_shape_or_spacing(): rolling_window(coords, size=2) -def test_rolling_window_oversized_window(): +@pytest.mark.parametrize( + "region", + [ + (-5, -1, 6, 20), # window larger than west-east + (-20, -1, 6, 10), # window larger than south-north + (-5, -1, 6, 10), # window larger than both dims + ], +) +def test_rolling_window_oversized_window(region): """ Check if error is raised if size larger than region is passed """ oversize = 5 - regions = [ - (-5, -1, 6, 20), # window larger than west-east - (-20, -1, 6, 10), # window larger than south-north - (-5, -1, 6, 10), # window larger than both dims - ] - for region in regions: - coords = grid_coordinates(region, spacing=1) - # The expected error message with regex - # (the long expression intends to capture floats and ints) - float_regex = r"[+-]?([0-9]*[.])?[0-9]+" - err_msg = ( - r"Window size '{}' is larger ".format(float_regex) - + r"than dimensions of the region " - + r"'\({0}, {0}, {0}, {0}\)'.".format(float_regex) - ) - with pytest.raises(ValueError, match=err_msg): - rolling_window(coords, size=oversize, spacing=2) + coords = grid_coordinates(region, spacing=1) + err_msg = f"Window size '{oversize}' is larger than dimensions of the region " + with pytest.raises(ValueError, match=err_msg): + rolling_window(coords, size=oversize, spacing=2) def test_spacing_to_size(): diff --git a/verde/utils.py b/verde/utils.py index a12748d0d..0d7ee6c60 100644 --- a/verde/utils.py +++ b/verde/utils.py @@ -196,18 +196,24 @@ def maxabs(*args, nan=True): Examples -------- - >>> maxabs((1, -10, 25, 2, 3)) - 25 - >>> maxabs((1, -10.5, 25, 2), (0.1, 100, -500), (-200, -300, -0.1, -499)) + >>> result = maxabs((1, -10, 25, 2, 3)) + >>> float(result) + 25.0 + >>> result = maxabs( + ... (1, -10.5, 25, 2), (0.1, 100, -500), (-200, -300, -0.1, -499) + ... ) + >>> float(result) 500.0 If the array contains NaNs, we'll use the ``nan`` version of of the numpy functions by default. You can turn this off through the *nan* argument. >>> import numpy as np - >>> maxabs((1, -10, 25, 2, 3, np.nan)) + >>> result = maxabs((1, -10, 25, 2, 3, np.nan)) + >>> float(result) 25.0 - >>> maxabs((1, -10, 25, 2, 3, np.nan), nan=False) + >>> result = maxabs((1, -10, 25, 2, 3, np.nan), nan=False) + >>> float(result) nan """