From 82f9142f0ffa5a73b396bc06fb6023480fc0f2c1 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 28 Dec 2025 22:23:20 +0530 Subject: [PATCH 1/3] Use ValueError instead of IndexError in _degrees_to_index --- pvlib/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/tools.py b/pvlib/tools.py index 142e89869b..6cb631f852 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -471,14 +471,14 @@ def _degrees_to_index(degrees, coordinate): inputmax = 180 outputmax = 4320 else: - raise IndexError("coordinate must be 'latitude' or 'longitude'.") + raise ValueError("coordinate must be 'latitude' or 'longitude'.") inputrange = inputmax - inputmin scale = outputmax/inputrange # number of indices per degree center = inputmin + 1 / scale / 2 # shift to center of index outputmax -= 1 # shift index to zero indexing index = (degrees - center) * scale - err = IndexError('Input, %g, is out of range (%g, %g).' % + err = ValueError('Input, %g, is out of range (%g, %g).' % (degrees, inputmin, inputmax)) # If the index is still out of bounds after rounding, raise an error. From 6718fbc7eacc690a867bdc0f10bc0edc8d1d111c Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 28 Dec 2025 22:31:40 +0530 Subject: [PATCH 2/3] Update tests to expect ValueError in _degrees_to_index --- tests/test_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 821b9fec65..11001cf0b0 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -102,7 +102,7 @@ def test__golden_sect_DataFrame_nans(): def test_degrees_to_index_1(): """Test that _degrees_to_index raises an error when something other than 'latitude' or 'longitude' is passed.""" - with pytest.raises(IndexError): # invalid value for coordinate argument + with pytest.raises(ValueError, match="coordinate must be"): # invalid value for coordinate argument tools._degrees_to_index(degrees=22.0, coordinate='width') From 1301160d7dbd6c9f7b5b2ee89c858320413d3992 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 28 Dec 2025 22:36:11 +0530 Subject: [PATCH 3/3] Fix flake8 line length in _degrees_to_index test --- tests/test_tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 11001cf0b0..4b733ad711 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -102,7 +102,8 @@ def test__golden_sect_DataFrame_nans(): def test_degrees_to_index_1(): """Test that _degrees_to_index raises an error when something other than 'latitude' or 'longitude' is passed.""" - with pytest.raises(ValueError, match="coordinate must be"): # invalid value for coordinate argument + # invalid value for coordinate argument + with pytest.raises(ValueError, match="coordinate must be"): tools._degrees_to_index(degrees=22.0, coordinate='width')