diff --git a/docs/sphinx/source/whatsnew/v0.9.2.rst b/docs/sphinx/source/whatsnew/v0.9.2.rst index dcce33370f..aebb65acba 100644 --- a/docs/sphinx/source/whatsnew/v0.9.2.rst +++ b/docs/sphinx/source/whatsnew/v0.9.2.rst @@ -24,6 +24,10 @@ Bug fixes where passing localized timezones with large UTC offsets could return rise/set/transit times for the wrong day in recent versions of ``ephem`` (:issue:`1449`, :pull:`1448`) +* :py:func:`pvlib.iotools.get_psm3` now raises a deprecation warning if + the `leap_day` parameter is not specified in a single-year request. + Starting in pvlib 0.11.0 `leap_day` will default to True instead of False. + (:issue:`1481`, :pull:`1511`) Testing diff --git a/pvlib/iotools/psm3.py b/pvlib/iotools/psm3.py index a8f9781c22..71e74dfd54 100644 --- a/pvlib/iotools/psm3.py +++ b/pvlib/iotools/psm3.py @@ -42,7 +42,7 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60, - attributes=ATTRIBUTES, leap_day=False, full_name=PVLIB_PYTHON, + attributes=ATTRIBUTES, leap_day=None, full_name=PVLIB_PYTHON, affiliation=PVLIB_PYTHON, map_variables=None, timeout=30): """ Retrieve NSRDB PSM3 timeseries weather data from the PSM3 API. The NSRDB @@ -165,6 +165,14 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60, attributes = [amap.get(a, a) for a in attributes] attributes = list(set(attributes)) # remove duplicate values + if (leap_day is None) and (not names.startswith('t')): + warnings.warn( + 'The ``get_psm3`` function will default to leap_day=True ' + 'starting in pvlib 0.11.0. Specify leap_day=True ' + 'to enable this behavior now, or specify leap_day=False ' + 'to hide this warning.', pvlibDeprecationWarning) + leap_day = False + # required query-string parameters for request to PSM3 API params = { 'api_key': api_key, diff --git a/pvlib/tests/iotools/test_psm3.py b/pvlib/tests/iotools/test_psm3.py index d151cfa6da..c02246c5bd 100644 --- a/pvlib/tests/iotools/test_psm3.py +++ b/pvlib/tests/iotools/test_psm3.py @@ -78,7 +78,7 @@ def test_get_psm3_tmy(nrel_api_key): """test get_psm3 with a TMY""" data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names='tmy-2017', - map_variables=False) + leap_day=False, map_variables=False) expected = pd.read_csv(TMY_TEST_DATA) assert_psm3_equal(data, metadata, expected) @@ -89,7 +89,8 @@ def test_get_psm3_singleyear(nrel_api_key): """test get_psm3 with a single year""" data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names='2017', - map_variables=False, interval=30) + leap_day=False, map_variables=False, + interval=30) expected = pd.read_csv(YEAR_TEST_DATA) assert_psm3_equal(data, metadata, expected) @@ -100,7 +101,7 @@ def test_get_psm3_5min(nrel_api_key): """test get_psm3 for 5-minute data""" data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names='2019', interval=5, - map_variables=False) + leap_day=False, map_variables=False) assert len(data) == 525600/5 first_day = data.loc['2019-01-01'] expected = pd.read_csv(YEAR_TEST_DATA_5MIN) @@ -137,7 +138,8 @@ def test_get_psm3_tmy_errors( """ with pytest.raises(HTTPError) as excinfo: psm3.get_psm3(latitude, longitude, api_key, PVLIB_EMAIL, - names=names, interval=interval, map_variables=False) + names=names, interval=interval, leap_day=False, + map_variables=False) # ensure the HTTPError caught isn't due to overuse of the API key assert "OVER_RATE_LIMIT" not in str(excinfo.value) @@ -186,7 +188,7 @@ def test_get_psm3_attribute_mapping(nrel_api_key): data, meta = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names=2019, interval=60, attributes=['ghi', 'wind_speed'], - map_variables=True) + leap_day=False, map_variables=True) assert 'ghi' in data.columns assert 'wind_speed' in data.columns assert 'latitude' in meta.keys() @@ -199,3 +201,14 @@ def test_get_psm3_attribute_mapping(nrel_api_key): def test_psm3_variable_map_deprecation_warning(nrel_api_key): with pytest.warns(pvlibDeprecationWarning, match='names will be renamed'): _ = psm3.read_psm3(MANUAL_TEST_DATA) + + +@pytest.mark.remote_data +@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) +def test_psm3_leap_day_deprecation_warning(nrel_api_key): + with pytest.warns(pvlibDeprecationWarning, + match='default to leap_day=True'): + _, _ = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, + names=2019, interval=60, + attributes=['ghi', 'wind_speed'], + map_variables=True)