Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pvlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions tests/test_clearsky.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import OrderedDict

import pytest
import numpy as np
from numpy import nan
import pandas as pd
Expand Down Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(IndexError): # 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')


Expand Down
Loading