Skip to content

Commit 440e780

Browse files
committed
change coerce_year and utc_offset defaults to None in pvgis TMY
- update arg docstrings - allow user to coerce year even if utc_offset is None or zero - use 1990 as default if utc_offset is not None or zero, but coerce_year was unspecified - add warning comment to be explicit and test identity to avoid unexpected implicit booleaness
1 parent a38cf9a commit 440e780

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pvlib/iotools/pvgis.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def _coerce_and_roll_pvgis_tmy(pvgis_data, tz, year):
409409
def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
410410
userhorizon=None, startyear=None, endyear=None,
411411
map_variables=True, url=URL, timeout=30,
412-
utc_offset=0, coerce_year=1990):
412+
utc_offset=None, coerce_year=None):
413413
"""
414414
Get TMY data from PVGIS.
415415
@@ -441,13 +441,13 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
441441
base url of PVGIS API, append ``tmy`` to get TMY endpoint
442442
timeout : int, default 30
443443
time in seconds to wait for server response before timeout
444-
utc_offset: int, default 0
444+
utc_offset: int, default None
445445
Use to specify a time zone other than the default UTC zero and roll
446-
dataframe by ``utc_offset`` so that it starts at midnight on January
447-
1st. If not zero, will also force year to ``coerce_year``.
448-
coerce_year: int, default 1990
449-
Use to force indices to desired year. Ignored if ``utc_offset`` is
450-
zero.
446+
dataframe by ``utc_offset`` so it starts at midnight on January 1st.
447+
Ignored if ``None``, otherwise will also force year to ``coerce_year``.
448+
coerce_year: int, default None
449+
Use to force indices to desired year. Will default to 1990 if
450+
``coerce_year`` is ``None``, but ``utc_offset`` is not ``None``.
451451
452452
Returns
453453
-------
@@ -534,7 +534,14 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
534534
if map_variables:
535535
data = data.rename(columns=VARIABLE_MAP)
536536

537-
if utc_offset != 0:
537+
if utc_offset is not None or coerce_year is not None:
538+
# XXX: be explicit, test for identity not implicit booleaness
539+
# utc_offset None but coerce_year isn't, set year with utc zero
540+
if utc_offset is None: # XXX: None and zero are both False
541+
utc_offset = 0
542+
# coerce_year is None but utc_off isn't, set year to 1990
543+
if coerce_year is None: # more explicit than (coerce_year or 1990)
544+
coerce_year = 1990
538545
data = _coerce_and_roll_pvgis_tmy(data, utc_offset, coerce_year)
539546

540547
return data, months_selected, inputs, meta

0 commit comments

Comments
 (0)