From 9915add2dc7f462b864a54c0f26656fb7dfdc0ac Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 28 Dec 2025 22:23:20 +0530 Subject: [PATCH 1/5] 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 2353a4b2e4a0b701094c00892f0bdccbca950189 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 28 Dec 2025 22:31:40 +0530 Subject: [PATCH 2/5] 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 b198edafb05709fe853d81e5173fea80bb644c25 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 28 Dec 2025 22:36:11 +0530 Subject: [PATCH 3/5] 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') From f13ae1a483681bf3619cb432235902f08105e006 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Wed, 21 Jan 2026 16:14:39 +0530 Subject: [PATCH 4/5] Update clearsky tests to expect ValueError for out-of-range lat/lon --- tests/test_clearsky.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_clearsky.py b/tests/test_clearsky.py index 296b96b345..9be640ae1c 100644 --- a/tests/test_clearsky.py +++ b/tests/test_clearsky.py @@ -1,5 +1,6 @@ from collections import OrderedDict +import pytest import numpy as np from numpy import nan import pandas as pd @@ -505,13 +506,13 @@ def monthly_lt_nointerp(lat, lon, time=months): monthly_lt_nointerp(-90, 180), [1.35, 1.7, 1.35, 1.35, 1.35, 1.35, 1.35, 1.35, 1.35, 1.35, 1.35, 1.7]) # test out of range exceptions at corners - with pytest.raises(IndexError): + with pytest.raises(ValueError, match="out of range"): monthly_lt_nointerp(91, -122) # exceeds max latitude - with pytest.raises(IndexError): + with pytest.raises(ValueError, match="out of range"): monthly_lt_nointerp(38.2, 181) # exceeds max longitude - with pytest.raises(IndexError): + with pytest.raises(ValueError, match="out of range"): monthly_lt_nointerp(-91, -122) # exceeds min latitude - with pytest.raises(IndexError): + with pytest.raises(ValueError, match="out of range"): monthly_lt_nointerp(38.2, -181) # exceeds min longitude From eaf3931c33b48c90322aaea42a42801813c50a3f Mon Sep 17 00:00:00 2001 From: Aman Srivastava <160766756+aman-coder03@users.noreply.github.com> Date: Wed, 4 Feb 2026 20:48:28 +0530 Subject: [PATCH 5/5] Update tests/test_clearsky.py Co-authored-by: Cliff Hansen --- tests/test_clearsky.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_clearsky.py b/tests/test_clearsky.py index 9be640ae1c..687dd9133e 100644 --- a/tests/test_clearsky.py +++ b/tests/test_clearsky.py @@ -1,6 +1,5 @@ from collections import OrderedDict -import pytest import numpy as np from numpy import nan import pandas as pd