@@ -371,9 +371,7 @@ def meta_expected():
371
371
372
372
@pytest .fixture
373
373
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' ]
377
375
378
376
379
377
@pytest .fixture
@@ -393,7 +391,15 @@ def test_get_pvgis_tmy(expected, month_year_expected, inputs_expected,
393
391
394
392
def _compare_pvgis_tmy_json (expected , month_year_expected , inputs_expected ,
395
393
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
+
397
403
# check each column of output separately
398
404
for outvar in meta_expected ['outputs' ]['tmy_hourly' ]['variables' ].keys ():
399
405
assert np .allclose (data [outvar ], expected [outvar ])
@@ -419,28 +425,27 @@ def _compare_pvgis_tmy_json(expected, month_year_expected, inputs_expected,
419
425
@pytest .mark .remote_data
420
426
@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
421
427
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 (
426
431
45 , 8 , userhorizon = [0 , 10 , 20 , 30 , 40 , 15 , 25 , 5 ], map_variables = False )
427
432
assert np .allclose (
428
433
data ['G(h)' ], userhorizon_expected ['G(h)' ].values )
429
434
assert np .allclose (
430
435
data ['Gb(n)' ], userhorizon_expected ['Gb(n)' ].values )
431
436
assert np .allclose (
432
437
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
437
442
438
443
439
444
@pytest .mark .remote_data
440
445
@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
441
446
def test_get_pvgis_tmy_coerce_year ():
442
447
"""test utc_offset and coerce_year work as expected"""
443
- base_case , _ , _ , _ = get_pvgis_tmy (45 , 8 ) # Turin
448
+ base_case , _ = get_pvgis_tmy (45 , 8 ) # Turin
444
449
assert str (base_case .index .tz ) == 'UTC'
445
450
assert base_case .index .name == 'time(UTC)'
446
451
noon_test_data = [
@@ -449,9 +454,9 @@ def test_get_pvgis_tmy_coerce_year():
449
454
cet_tz = 1 # Turin time is CET
450
455
cet_name = 'Etc/GMT-1'
451
456
# check indices of rolled data after converting timezone
452
- 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 )
457
+ pvgis_data , _ = get_pvgis_tmy (45 , 8 , roll_utc_offset = cet_tz )
458
+ jan1_midnight = pd .Timestamp ('1990-01-01 00' , tz = cet_name )
459
+ dec31_midnight = pd .Timestamp ('1990-12-31 23' , tz = cet_name )
455
460
assert pvgis_data .index [0 ] == jan1_midnight
456
461
assert pvgis_data .index [- 1 ] == dec31_midnight
457
462
assert pvgis_data .index .name == f'time({ cet_name } )'
@@ -461,20 +466,20 @@ def test_get_pvgis_tmy_coerce_year():
461
466
assert all (test_case == expected )
462
467
# repeat tests with year coerced
463
468
test_yr = 2021
464
- pvgis_data , _ , _ , _ = get_pvgis_tmy (
469
+ pvgis_data , _ = get_pvgis_tmy (
465
470
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 )
468
473
assert pvgis_data .index [0 ] == jan1_midnight
469
474
assert pvgis_data .index [- 1 ] == dec31_midnight
470
475
assert pvgis_data .index .name == f'time({ cet_name } )'
471
476
for m , test_case in enumerate (noon_test_data ):
472
477
expected = pvgis_data [pvgis_data .index .month == m + 1 ].iloc [12 + cet_tz ]
473
478
assert all (test_case == expected )
474
479
# repeat tests with year coerced but utc offset none or zero
475
- 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' )
480
+ pvgis_data , _ = get_pvgis_tmy (45 , 8 , coerce_year = test_yr )
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' )
478
483
assert pvgis_data .index [0 ] == jan1_midnight
479
484
assert pvgis_data .index [- 1 ] == dec31_midnight
480
485
assert pvgis_data .index .name == 'time(UTC)'
@@ -494,7 +499,13 @@ def test_get_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
494
499
495
500
def _compare_pvgis_tmy_csv (expected , month_year_expected , inputs_expected ,
496
501
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
+
498
509
# check each column of output separately
499
510
for outvar in meta_expected ['outputs' ]['tmy_hourly' ]['variables' ].keys ():
500
511
assert np .allclose (data [outvar ], expected [outvar ])
@@ -526,7 +537,7 @@ def test_get_pvgis_tmy_epw(expected, epw_meta):
526
537
527
538
528
539
def _compare_pvgis_tmy_epw (expected , epw_meta , pvgis_data ):
529
- data , _ , _ , meta = pvgis_data
540
+ data , meta = pvgis_data
530
541
assert np .allclose (data .ghi , expected ['G(h)' ])
531
542
assert np .allclose (data .dni , expected ['Gb(n)' ])
532
543
assert np .allclose (data .dhi , expected ['Gd(h)' ])
@@ -556,8 +567,8 @@ def test_get_pvgis_tmy_basic():
556
567
557
568
@pytest .mark .remote_data
558
569
@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
559
- def test_get_pvgis_map_variables (pvgis_tmy_mapped_columns ):
560
- actual , _ , _ , _ = get_pvgis_tmy (45 , 8 , map_variables = True )
570
+ def test_get_pvgis_tmy_map_variables (pvgis_tmy_mapped_columns ):
571
+ actual , _ = get_pvgis_tmy (45 , 8 , map_variables = True )
561
572
assert all (c in pvgis_tmy_mapped_columns for c in actual .columns )
562
573
563
574
@@ -580,7 +591,7 @@ def test_read_pvgis_horizon_invalid_coords():
580
591
581
592
def test_read_pvgis_tmy_map_variables (pvgis_tmy_mapped_columns ):
582
593
fn = TESTS_DATA_DIR / 'tmy_45.000_8.000_2005_2023.json'
583
- actual , _ , _ , _ = read_pvgis_tmy (fn , map_variables = True )
594
+ actual , _ = read_pvgis_tmy (fn , map_variables = True )
584
595
assert all (c in pvgis_tmy_mapped_columns for c in actual .columns )
585
596
586
597
0 commit comments