From 82f9142f0ffa5a73b396bc06fb6023480fc0f2c1 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 28 Dec 2025 22:23:20 +0530 Subject: [PATCH 1/4] 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/4] 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/4] 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 550468f2d156c23cf3247720940eeb31e5e448b3 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Wed, 21 Jan 2026 16:14:39 +0530 Subject: [PATCH 4/4] 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