@@ -429,16 +429,18 @@ def _generate_solarposition_dataframe(inputs, algorithm, **kwargs):
429429 if row ['elevation' ] is not None :
430430 if algorithm .__name__ in ['sg2' , 'sg2_c' , 'spa' ]:
431431 elevation_dict ['elevation' ] = row ['elevation' ]
432+ # calculate for two identical indexes to make sure
433+ # indexes with more than one element works
432434 dfi = algorithm (
433- pd .DatetimeIndex ([index ]),
435+ pd .DatetimeIndex ([index , index ]),
434436 row ['latitude' ],
435437 row ['longitude' ],
436438 ** {** kwargs , ** elevation_dict },
437439 )
438440 except ValueError :
439441 # Add empty row (nans)
440442 dfi = pd .DataFrame (index = [index ])
441- dfs .append (dfi )
443+ dfs .append (dfi . iloc [ 0 : 1 ] )
442444 df = pd .concat (dfs , axis = 'rows' )
443445 return df
444446
@@ -651,3 +653,18 @@ def test_site_elevation_sg2():
651653 none_elevation = sg2 (times , latitude , longitude )
652654 assert zero_elevation .iloc [0 ]['elevation' ] != high_elevation .iloc [0 ]['elevation' ]
653655 assert zero_elevation .iloc [0 ]['elevation' ] == none_elevation .iloc [0 ]['elevation' ]
656+
657+
658+ def test_sg2_year_out_of_range ():
659+ with pytest .raises (ValueError ,
660+ match = 'valid only between 1980 and 2030' ):
661+ _ = sg2 (
662+ times = pd .date_range ('1960-01-01' , '1960-01-02' , tz = 'UTC' ),
663+ latitude = 50 , longitude = 10 ,
664+ )
665+ with pytest .raises (ValueError ,
666+ match = 'valid only between 1980 and 2030' ):
667+ _ = sg2 (
668+ times = pd .date_range ('2035-01-01' , '2035-01-02' , tz = 'UTC' ),
669+ latitude = 50 , longitude = 10 ,
670+ )
0 commit comments