Skip to content

Commit

Permalink
Merge branch 'main' into codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
santisoler authored Aug 27, 2024
2 parents 0581b26 + db1fa19 commit 9299b2c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- pip
# Build
- twine
- build
- python-build
# Run
- numpy
- scipy
Expand Down
10 changes: 2 additions & 8 deletions verde/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
Expand Down Expand Up @@ -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,)
Expand Down Expand Up @@ -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. ]
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion verde/projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
Expand Down
31 changes: 13 additions & 18 deletions verde/tests/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
16 changes: 11 additions & 5 deletions verde/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down

0 comments on commit 9299b2c

Please sign in to comment.