@@ -250,6 +250,9 @@ def sampled_moving_average(
250
250
prediction (i.e. the moving average) corresponding to the ground truth
251
251
does not include the ground truth itself. This can be achieved by
252
252
shifting the Series by sampling_interval.
253
+
254
+ Raises:
255
+ TypeError: If the output is not a pandas Series.
253
256
"""
254
257
sampling_interval = abs (int (sampling_interval ))
255
258
data_index = pd .to_datetime (data .index ).to_series ()
@@ -270,7 +273,8 @@ def sampled_moving_average(
270
273
).apply (lambda x : x [::sampling_interval ].mean (), raw = True )
271
274
if isinstance (predictions , pd .DataFrame ):
272
275
predictions = predictions .squeeze ()
273
- assert isinstance (predictions , pd .Series ) # for type checker
276
+ if not isinstance (predictions , pd .Series ):
277
+ raise TypeError ("Output is not a pandas Series." )
274
278
predictions .name = "predictions"
275
279
return predictions
276
280
@@ -303,7 +307,8 @@ def naive_efficiency_factor_irr_to_power( # pylint: disable=too-many-arguments
303
307
A pandas Series containing the predicted power (in kilo-Watts) output.
304
308
305
309
Raises:
306
- ValueError: If the input dataframe contains duplicate index entries.
310
+ ValueError: If the input dataframe contains duplicate index entries or
311
+ if the validity_ts is not unique.
307
312
"""
308
313
data_copy = data .copy (deep = True )
309
314
data_copy .sort_values (by = ["creation_ts" , "validity_ts" ], inplace = True )
@@ -319,9 +324,8 @@ def naive_efficiency_factor_irr_to_power( # pylint: disable=too-many-arguments
319
324
to_include .loc [to_include .index [position + 1 :]] = True
320
325
data_copy = data_copy [to_include ]
321
326
322
- assert (
323
- data_copy .validity_ts .nunique () == data_copy .validity_ts .count ()
324
- ), "validity_ts is not unique"
327
+ if data_copy .validity_ts .nunique () != data_copy .validity_ts .count ():
328
+ raise ValueError ("validity_ts is not unique" )
325
329
data_copy .set_index ("validity_ts" , inplace = True )
326
330
data_copy .index .name = "timestamp"
327
331
if resample_rate :
@@ -450,6 +454,9 @@ def _get_pvgis_hourly(
450
454
Returns:
451
455
A pandas DataFrame containing the hourly data.
452
456
457
+ Raises:
458
+ ValueError: If the minute values in the index are not unique.
459
+
453
460
References:
454
461
- https://pvlib-python.readthedocs.io/en/stable/reference/generated/
455
462
pvlib.iotools.get_pvgis_hourly.html
@@ -462,7 +469,8 @@ def _get_pvgis_hourly(
462
469
raddatabase = "PVGIS-SARAH2" ,
463
470
url = "https://re.jrc.ec.europa.eu/api/v5_2/" ,
464
471
)
465
- assert pvgis_df .index .minute .nunique () == 1 # sanity check
472
+ if pvgis_df .index .minute .nunique () != 1 :
473
+ raise ValueError ("Minute values in the index are not unique." )
466
474
pvgis_df .index = pvgis_df .index - pd .Timedelta (
467
475
minutes = pvgis_df .index .minute .unique ()[0 ]
468
476
)
0 commit comments