Skip to content

Commit 4693f31

Browse files
committed
Fix tests, whatsnew, linter
1 parent da202e2 commit 4693f31

3 files changed

Lines changed: 40 additions & 27 deletions

File tree

docs/sphinx/source/whatsnew/v0.12.1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Breaking Changes
1414
* The functions :py:func:`~pvlib.iotools.read_pvgis_tmy` and
1515
:py:func:`~pvlib.iotools.get_pvgis_tmy` now return ``(data,meta)``
1616
following the iotools convention instead of ``(data,months_selected,inputs,meta)``.
17-
(:pull:`XXXX`)
17+
(:pull:`2470`)
1818
* Remove ``outputformat='basic'`` option in :py:func:`~pvlib.iotools.get_pvgis_tmy`.
1919
(:pull:`2416`)
2020

pvlib/iotools/pvgis.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,9 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
443443
.. versionchanged:: 0.13.0
444444
The function now returns two items ``(data,meta)``. Previous
445445
versions of this function returned three elements
446-
``(data,months_selected,inputs,meta)``. The ``inputs`` dictionary and
447-
``months_selected`` are now included in ``meta``, which has changed
448-
structure to accommodate it.
446+
``(data,months_selected,inputs,meta)``. The ``inputs`` dictionary
447+
and ``months_selected`` are now included in ``meta``, which has
448+
changed structure to accommodate it.
449449
450450
Parameters
451451
----------
@@ -607,7 +607,9 @@ def _parse_pvgis_tmy_csv(src):
607607
data = pd.DataFrame(data, dtype=float)
608608
data.index = dtidx
609609
# finally there's some meta data
610+
meta['descriptions'] = {}
610611
for line in src.readlines():
612+
line = line.decode('utf-8').strip()
611613
if ':' in line:
612614
meta['descriptions'][line.split(':')[0]] = \
613615
line.split(':')[1].strip()
@@ -621,9 +623,9 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
621623
.. versionchanged:: 0.13.0
622624
The function now returns two items ``(data,meta)``. Previous
623625
versions of this function returned three elements
624-
``(data,months_selected,inputs,meta)``. The ``inputs`` dictionary and
625-
``months_selected`` are now included in ``meta``, which has changed
626-
structure to accommodate it.
626+
``(data,months_selected,inputs,meta)``. The ``inputs`` dictionary
627+
and ``months_selected`` are now included in ``meta``, which has
628+
changed structure to accommodate it.
627629
628630
Parameters
629631
----------

tests/iotools/test_pvgis.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,7 @@ def meta_expected():
371371

372372
@pytest.fixture
373373
def csv_meta(meta_expected):
374-
return [
375-
f"{k}: {v['description']} ({v['units']})" for k, v
376-
in meta_expected['outputs']['tmy_hourly']['variables'].items()]
374+
return meta_expected['outputs']['tmy_hourly']['variables']
377375

378376

379377
@pytest.fixture
@@ -393,7 +391,15 @@ def test_get_pvgis_tmy(expected, month_year_expected, inputs_expected,
393391

394392
def _compare_pvgis_tmy_json(expected, month_year_expected, inputs_expected,
395393
meta_expected, pvgis_data):
396-
data, months_selected, inputs, meta = pvgis_data
394+
data, meta = pvgis_data
395+
396+
# Re-create original outputs (prior to #2470)
397+
months_selected = meta['months_selected']
398+
inputs = meta['inputs'].copy()
399+
del inputs['descriptions']
400+
meta['inputs'] = meta['inputs']['descriptions']
401+
del meta['months_selected']
402+
397403
# check each column of output separately
398404
for outvar in meta_expected['outputs']['tmy_hourly']['variables'].keys():
399405
assert np.allclose(data[outvar], expected[outvar])
@@ -419,21 +425,20 @@ def _compare_pvgis_tmy_json(expected, month_year_expected, inputs_expected,
419425
@pytest.mark.remote_data
420426
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
421427
def test_get_pvgis_tmy_kwargs(userhorizon_expected):
422-
_, _, inputs, _ = get_pvgis_tmy(45, 8, usehorizon=False,
423-
map_variables=False)
424-
assert inputs['meteo_data']['use_horizon'] is False
425-
data, _, _, _ = get_pvgis_tmy(
428+
_, meta = get_pvgis_tmy(45, 8, usehorizon=False, map_variables=False)
429+
assert meta['inputs']['meteo_data']['use_horizon'] is False
430+
data, _ = get_pvgis_tmy(
426431
45, 8, userhorizon=[0, 10, 20, 30, 40, 15, 25, 5], map_variables=False)
427432
assert np.allclose(
428433
data['G(h)'], userhorizon_expected['G(h)'].values)
429434
assert np.allclose(
430435
data['Gb(n)'], userhorizon_expected['Gb(n)'].values)
431436
assert np.allclose(
432437
data['Gd(h)'], userhorizon_expected['Gd(h)'].values)
433-
_, _, inputs, _ = get_pvgis_tmy(45, 8, startyear=2005, map_variables=False)
434-
assert inputs['meteo_data']['year_min'] == 2005
435-
_, _, inputs, _ = get_pvgis_tmy(45, 8, endyear=2016, map_variables=False)
436-
assert inputs['meteo_data']['year_max'] == 2016
438+
_, meta = get_pvgis_tmy(45, 8, startyear=2005, map_variables=False)
439+
assert meta['inputs']['meteo_data']['year_min'] == 2005
440+
_, meta = get_pvgis_tmy(45, 8, endyear=2016, map_variables=False)
441+
assert meta['inputs']['meteo_data']['year_max'] == 2016
437442

438443

439444
@pytest.mark.remote_data
@@ -450,8 +455,8 @@ def test_get_pvgis_tmy_coerce_year():
450455
cet_name = 'Etc/GMT-1'
451456
# check indices of rolled data after converting timezone
452457
pvgis_data, _ = get_pvgis_tmy(45, 8, roll_utc_offset=cet_tz)
453-
jan1_midnight = pd.Timestamp('1990-01-01 00:00:00', tz=cet_name)
454-
dec31_midnight = pd.Timestamp('1990-12-31 23:00:00', tz=cet_name)
458+
jan1_midnight = pd.Timestamp('1990-01-01 00', tz=cet_name)
459+
dec31_midnight = pd.Timestamp('1990-12-31 23', tz=cet_name)
455460
assert pvgis_data.index[0] == jan1_midnight
456461
assert pvgis_data.index[-1] == dec31_midnight
457462
assert pvgis_data.index.name == f'time({cet_name})'
@@ -463,8 +468,8 @@ def test_get_pvgis_tmy_coerce_year():
463468
test_yr = 2021
464469
pvgis_data, _ = get_pvgis_tmy(
465470
45, 8, roll_utc_offset=cet_tz, coerce_year=test_yr)
466-
jan1_midnight = pd.Timestamp(f'{test_yr}-01-01 00:00:00', tz=cet_name)
467-
dec31_midnight = pd.Timestamp(f'{test_yr}-12-31 23:00:00', tz=cet_name)
471+
jan1_midnight = pd.Timestamp(f'{test_yr}-01-01 00', tz=cet_name)
472+
dec31_midnight = pd.Timestamp(f'{test_yr}-12-31 23', tz=cet_name)
468473
assert pvgis_data.index[0] == jan1_midnight
469474
assert pvgis_data.index[-1] == dec31_midnight
470475
assert pvgis_data.index.name == f'time({cet_name})'
@@ -473,8 +478,8 @@ def test_get_pvgis_tmy_coerce_year():
473478
assert all(test_case == expected)
474479
# repeat tests with year coerced but utc offset none or zero
475480
pvgis_data, _ = get_pvgis_tmy(45, 8, coerce_year=test_yr)
476-
jan1_midnight = pd.Timestamp(f'{test_yr}-01-01 00:00:00', tz='UTC')
477-
dec31_midnight = pd.Timestamp(f'{test_yr}-12-31 23:00:00', tz='UTC')
481+
jan1_midnight = pd.Timestamp(f'{test_yr}-01-01 00', tz='UTC')
482+
dec31_midnight = pd.Timestamp(f'{test_yr}-12-31 23', tz='UTC')
478483
assert pvgis_data.index[0] == jan1_midnight
479484
assert pvgis_data.index[-1] == dec31_midnight
480485
assert pvgis_data.index.name == 'time(UTC)'
@@ -494,7 +499,13 @@ def test_get_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
494499

495500
def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
496501
meta_expected, csv_meta, pvgis_data):
497-
data, months_selected, inputs, meta = pvgis_data
502+
data, meta = pvgis_data
503+
504+
# Re-create original outputs (prior to #2470)
505+
months_selected = meta['months_selected']
506+
inputs = meta['inputs'].copy()
507+
meta = meta['descriptions']
508+
498509
# check each column of output separately
499510
for outvar in meta_expected['outputs']['tmy_hourly']['variables'].keys():
500511
assert np.allclose(data[outvar], expected[outvar])
@@ -526,7 +537,7 @@ def test_get_pvgis_tmy_epw(expected, epw_meta):
526537

527538

528539
def _compare_pvgis_tmy_epw(expected, epw_meta, pvgis_data):
529-
data, _, _, meta = pvgis_data
540+
data, meta = pvgis_data
530541
assert np.allclose(data.ghi, expected['G(h)'])
531542
assert np.allclose(data.dni, expected['Gb(n)'])
532543
assert np.allclose(data.dhi, expected['Gd(h)'])

0 commit comments

Comments
 (0)