Describe the issue
The helper function _degrees_to_index raises IndexError for invalid
input values and arguments, but these cases represent invalid values
rather than invalid indexing.
Using IndexError here is semantically incorrect and inconsistent with
standard Python and NumPy error conventions.
Location in code
In pvlib/tools.py (function _degrees_to_index):
raise IndexError("coordinate must be 'latitude' or 'longitude'.")
and later:
err = IndexError(
'Input, %g, is out of range (%g, %g).' % (degrees, inputmin, inputmax)
)
Why this is a problem?
IndexError is intended for invalid indexing operations (e.g. list or
array indices).
These errors are caused by invalid argument values supplied by the
user.
The appropriate exception type in this context is ValueError.
Using ValueError would:
Better reflect the nature of the error
Align with Python and NumPy conventions
Improve API correctness and clarity for users