From 62aae52cd57efc00947d700d1cea4f27d2a54d6b Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Mon, 1 Aug 2022 22:38:58 +0200 Subject: [PATCH 1/5] Add deprecation for leap_day --- pvlib/iotools/psm3.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pvlib/iotools/psm3.py b/pvlib/iotools/psm3.py index a8f9781c22..e92bd43998 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: + 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, From 5a755fc3dc7cc08abf99621cd0b7112cd17fd27f Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Mon, 1 Aug 2022 22:39:05 +0200 Subject: [PATCH 2/5] Add test coverage --- pvlib/tests/iotools/test_psm3.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) 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) From e14406fc2d4943ac6222901287905f180fc15253 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Tue, 2 Aug 2022 08:23:28 +0200 Subject: [PATCH 3/5] Do not raise warning for TMY requests --- docs/sphinx/source/whatsnew/v0.9.2.rst | 4 ++++ pvlib/iotools/psm3.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.9.2.rst b/docs/sphinx/source/whatsnew/v0.9.2.rst index dcce33370f..a2473155f7 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. Starting in pvlib 0.11.0 + `leap_day` will be default to True instead of False. + (:issue:`1481`, :pull:`1511`) Testing diff --git a/pvlib/iotools/psm3.py b/pvlib/iotools/psm3.py index e92bd43998..36bf6880ab 100644 --- a/pvlib/iotools/psm3.py +++ b/pvlib/iotools/psm3.py @@ -165,7 +165,7 @@ 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: + if (leap_day is None) & (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 ' From adb8a1e3dacb9b12c5ae3069ad3d306d66075cc2 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:20:12 +0200 Subject: [PATCH 4/5] Replace & by and, and update whatsnew --- docs/sphinx/source/whatsnew/v0.9.2.rst | 6 +++--- pvlib/iotools/psm3.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.9.2.rst b/docs/sphinx/source/whatsnew/v0.9.2.rst index a2473155f7..1e479089a4 100644 --- a/docs/sphinx/source/whatsnew/v0.9.2.rst +++ b/docs/sphinx/source/whatsnew/v0.9.2.rst @@ -24,9 +24,9 @@ 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. Starting in pvlib 0.11.0 - `leap_day` will be default to True instead of False. +* :py:func:`pvlib.iotools.get_psm3` now raises a deprecation warning for + single-year requests where the `leap_day` parameter is not specified. + Starting in pvlib 0.11.0 `leap_day` will default to True instead of False. (:issue:`1481`, :pull:`1511`) diff --git a/pvlib/iotools/psm3.py b/pvlib/iotools/psm3.py index 36bf6880ab..71e74dfd54 100644 --- a/pvlib/iotools/psm3.py +++ b/pvlib/iotools/psm3.py @@ -165,7 +165,7 @@ 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) & (not names.startswith('t')): + 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 ' From 3c42c7b888a2b3224e9c1740e49846efd48b9368 Mon Sep 17 00:00:00 2001 From: "Adam R. Jensen" <39184289+AdamRJensen@users.noreply.github.com> Date: Fri, 5 Aug 2022 17:55:42 +0200 Subject: [PATCH 5/5] Update whatsnew Update whatsnew with suggestion from cwhanse Co-authored-by: Cliff Hansen --- docs/sphinx/source/whatsnew/v0.9.2.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.9.2.rst b/docs/sphinx/source/whatsnew/v0.9.2.rst index 1e479089a4..aebb65acba 100644 --- a/docs/sphinx/source/whatsnew/v0.9.2.rst +++ b/docs/sphinx/source/whatsnew/v0.9.2.rst @@ -24,8 +24,8 @@ 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 for - single-year requests where the `leap_day` parameter is not specified. +* :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`)