Skip to content

Commit e659a5a

Browse files
AdamRJensencwhanse
andauthored
Make leap_day=True default for PSM3 (deprecation) (#1511)
* Add deprecation for leap_day * Add test coverage * Do not raise warning for TMY requests * Replace & by and, and update whatsnew * Update whatsnew Update whatsnew with suggestion from cwhanse Co-authored-by: Cliff Hansen <[email protected]> Co-authored-by: Cliff Hansen <[email protected]>
1 parent 65e6fb3 commit e659a5a

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

docs/sphinx/source/whatsnew/v0.9.2.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Bug fixes
2727
where passing localized timezones with large UTC offsets could return
2828
rise/set/transit times for the wrong day in recent versions of ``ephem``
2929
(:issue:`1449`, :pull:`1448`)
30+
* :py:func:`pvlib.iotools.get_psm3` now raises a deprecation warning if
31+
the `leap_day` parameter is not specified in a single-year request.
32+
Starting in pvlib 0.11.0 `leap_day` will default to True instead of False.
33+
(:issue:`1481`, :pull:`1511`)
3034

3135

3236
Testing

pvlib/iotools/psm3.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343

4444
def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
45-
attributes=ATTRIBUTES, leap_day=False, full_name=PVLIB_PYTHON,
45+
attributes=ATTRIBUTES, leap_day=None, full_name=PVLIB_PYTHON,
4646
affiliation=PVLIB_PYTHON, map_variables=None, timeout=30):
4747
"""
4848
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,
165165
attributes = [amap.get(a, a) for a in attributes]
166166
attributes = list(set(attributes)) # remove duplicate values
167167

168+
if (leap_day is None) and (not names.startswith('t')):
169+
warnings.warn(
170+
'The ``get_psm3`` function will default to leap_day=True '
171+
'starting in pvlib 0.11.0. Specify leap_day=True '
172+
'to enable this behavior now, or specify leap_day=False '
173+
'to hide this warning.', pvlibDeprecationWarning)
174+
leap_day = False
175+
168176
# required query-string parameters for request to PSM3 API
169177
params = {
170178
'api_key': api_key,

pvlib/tests/iotools/test_psm3.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_get_psm3_tmy(nrel_api_key):
7878
"""test get_psm3 with a TMY"""
7979
data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
8080
PVLIB_EMAIL, names='tmy-2017',
81-
map_variables=False)
81+
leap_day=False, map_variables=False)
8282
expected = pd.read_csv(TMY_TEST_DATA)
8383
assert_psm3_equal(data, metadata, expected)
8484

@@ -89,7 +89,8 @@ def test_get_psm3_singleyear(nrel_api_key):
8989
"""test get_psm3 with a single year"""
9090
data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
9191
PVLIB_EMAIL, names='2017',
92-
map_variables=False, interval=30)
92+
leap_day=False, map_variables=False,
93+
interval=30)
9394
expected = pd.read_csv(YEAR_TEST_DATA)
9495
assert_psm3_equal(data, metadata, expected)
9596

@@ -100,7 +101,7 @@ def test_get_psm3_5min(nrel_api_key):
100101
"""test get_psm3 for 5-minute data"""
101102
data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
102103
PVLIB_EMAIL, names='2019', interval=5,
103-
map_variables=False)
104+
leap_day=False, map_variables=False)
104105
assert len(data) == 525600/5
105106
first_day = data.loc['2019-01-01']
106107
expected = pd.read_csv(YEAR_TEST_DATA_5MIN)
@@ -137,7 +138,8 @@ def test_get_psm3_tmy_errors(
137138
"""
138139
with pytest.raises(HTTPError) as excinfo:
139140
psm3.get_psm3(latitude, longitude, api_key, PVLIB_EMAIL,
140-
names=names, interval=interval, map_variables=False)
141+
names=names, interval=interval, leap_day=False,
142+
map_variables=False)
141143
# ensure the HTTPError caught isn't due to overuse of the API key
142144
assert "OVER_RATE_LIMIT" not in str(excinfo.value)
143145

@@ -186,7 +188,7 @@ def test_get_psm3_attribute_mapping(nrel_api_key):
186188
data, meta = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL,
187189
names=2019, interval=60,
188190
attributes=['ghi', 'wind_speed'],
189-
map_variables=True)
191+
leap_day=False, map_variables=True)
190192
assert 'ghi' in data.columns
191193
assert 'wind_speed' in data.columns
192194
assert 'latitude' in meta.keys()
@@ -199,3 +201,14 @@ def test_get_psm3_attribute_mapping(nrel_api_key):
199201
def test_psm3_variable_map_deprecation_warning(nrel_api_key):
200202
with pytest.warns(pvlibDeprecationWarning, match='names will be renamed'):
201203
_ = psm3.read_psm3(MANUAL_TEST_DATA)
204+
205+
206+
@pytest.mark.remote_data
207+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
208+
def test_psm3_leap_day_deprecation_warning(nrel_api_key):
209+
with pytest.warns(pvlibDeprecationWarning,
210+
match='default to leap_day=True'):
211+
_, _ = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL,
212+
names=2019, interval=60,
213+
attributes=['ghi', 'wind_speed'],
214+
map_variables=True)

0 commit comments

Comments
 (0)