Skip to content

Commit 33e15a5

Browse files
committed
Remove pvgis_tmy outputformat='basic' option
1 parent c83ecc7 commit 33e15a5

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

pvlib/iotools/pvgis.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,12 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
520520
with io.StringIO(res.content.decode('utf-8')) as src:
521521
data, meta = parse_epw(src)
522522
months_selected, inputs = None, None
523+
# raise exception if pvgis format isn't in ['csv', 'json', 'epw']
523524
else:
524-
# this line is never reached because if outputformat is not valid then
525-
# the response is HTTP/1.1 400 BAD REQUEST which is handled earlier
526-
pass
525+
err_msg = (
526+
"pvgis format '{:s}' was unknown, must be either 'json', 'csv', or 'epw'.")\
527+
.format(outputformat)
528+
raise ValueError(err_msg)
527529

528530
if map_variables:
529531
data = data.rename(columns=VARIABLE_MAP)

tests/iotools/test_pvgis.py

+7-32
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ def test_get_pvgis_hourly_bad_outputformat(requests_mock):
279279
get_pvgis_hourly(latitude=45, longitude=8, outputformat='basic')
280280

281281

282+
def test_get_pvgis_tmy_basic_outputformat():
283+
# Test if a ValueError is raised if an unsupported outputformat is used
284+
# E.g. 'basic' is a valid PVGIS format, but is not supported by pvlib
285+
with pytest.raises(ValueError):
286+
get_pvgis_tmy(latitude=45, longitude=8, outputformat='basic')
287+
288+
282289
url_additional_inputs = 'https://re.jrc.ec.europa.eu/api/seriescalc?lat=55.6814&lon=12.5758&outputformat=csv&angle=0&aspect=0&pvcalculation=1&pvtechchoice=crystSi&mountingplace=free&trackingtype=0&components=1&usehorizon=1&optimalangles=1&optimalinclination=0&loss=2&userhorizon=10%2C15%2C20%2C10&peakpower=5' # noqa: E501
283290

284291

@@ -427,21 +434,6 @@ def test_get_pvgis_tmy_kwargs(userhorizon_expected):
427434
assert inputs['meteo_data']['year_max'] == 2016
428435

429436

430-
@pytest.mark.remote_data
431-
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
432-
def test_get_pvgis_tmy_basic(expected, meta_expected):
433-
pvgis_data = get_pvgis_tmy(45, 8, outputformat='basic',
434-
map_variables=False)
435-
_compare_pvgis_tmy_basic(expected, meta_expected, pvgis_data)
436-
437-
438-
def _compare_pvgis_tmy_basic(expected, meta_expected, pvgis_data):
439-
data, _, _, _ = pvgis_data
440-
# check each column of output separately
441-
for outvar in meta_expected['outputs']['tmy_hourly']['variables'].keys():
442-
assert np.allclose(data[outvar], expected[outvar])
443-
444-
445437
@pytest.mark.remote_data
446438
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
447439
def test_get_pvgis_tmy_coerce_year():
@@ -630,23 +622,6 @@ def test_read_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
630622
meta_expected, csv_meta, pvgis_data)
631623

632624

633-
def test_read_pvgis_tmy_basic(expected, meta_expected):
634-
fn = TESTS_DATA_DIR / 'tmy_45.000_8.000_2005_2023.txt'
635-
# XXX: can't infer outputformat from file extensions for basic
636-
with pytest.raises(ValueError, match="pvgis format 'txt' was unknown"):
637-
read_pvgis_tmy(fn, map_variables=False)
638-
# explicit pvgis outputformat
639-
pvgis_data = read_pvgis_tmy(fn, pvgis_format='basic', map_variables=False)
640-
_compare_pvgis_tmy_basic(expected, meta_expected, pvgis_data)
641-
with fn.open('rb') as fbuf:
642-
pvgis_data = read_pvgis_tmy(fbuf, pvgis_format='basic',
643-
map_variables=False)
644-
_compare_pvgis_tmy_basic(expected, meta_expected, pvgis_data)
645-
# file buffer raises TypeError if passed to pathlib.Path()
646-
with pytest.raises(TypeError):
647-
read_pvgis_tmy(fbuf, map_variables=False)
648-
649-
650625
def test_read_pvgis_tmy_exception():
651626
bad_outputformat = 'bad'
652627
err_msg = f"pvgis format '{bad_outputformat:s}' was unknown"

0 commit comments

Comments
 (0)