Skip to content

Commit c3df9a8

Browse files
committed
Address wholmgren's review on PR #2705
- Rename nrel_api_key fixture to nlr_api_key directly (no alias) - Simplify fixture: check NLR_API_KEY, warn with DEMO_KEY fallback (no NREL_API_KEY deprecation logic) - Update test_psm4.py to use nlr_api_key fixture - Remove NREL_API_KEY from CI workflow - Update whatsnew: remove fallback mention, link nrel_nlr doc page
1 parent 1820fdd commit c3df9a8

4 files changed

Lines changed: 33 additions & 39 deletions

File tree

.github/workflows/pytest-remote-data.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ jobs:
9797
env:
9898
# copy GitHub Secrets into environment variables for the tests to access
9999
NLR_API_KEY: ${{ secrets.NRELAPIKEY }}
100-
NREL_API_KEY: ${{ secrets.NRELAPIKEY }}
101100
SOLARANYWHERE_API_KEY: ${{ secrets.SOLARANYWHERE_API_KEY }}
102101
BSRN_FTP_USERNAME: ${{ secrets.BSRN_FTP_USERNAME }}
103102
BSRN_FTP_PASSWORD: ${{ secrets.BSRN_FTP_PASSWORD }}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ Maintenance
5858
~~~~~~~~~~~
5959
* Update all NREL references to NLR (National Laboratory of the Rockies)
6060
following the laboratory rename and domain migration from ``nrel.gov``
61-
to ``nlr.gov``. Add ``NLR_API_KEY`` environment variable support with
62-
``NREL_API_KEY`` fallback. (:issue:`2701`, :pull:`2705`)
61+
to ``nlr.gov``. Rename ``NREL_API_KEY`` environment variable to
62+
``NLR_API_KEY``. See :ref:`nrel_nlr` for details.
63+
(:issue:`2701`, :pull:`2705`)
6364

6465

6566
Contributors

tests/conftest.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,27 @@ def assert_frame_equal(left, right, **kwargs):
8686

8787

8888
@pytest.fixture(scope="module")
89-
def nrel_api_key():
90-
"""API key for NLR Developer Network (formerly NREL).
91-
92-
Checks NLR_API_KEY first, falls back to NREL_API_KEY
93-
with deprecation warning.
89+
def nlr_api_key():
90+
"""Supplies pvlib-python's NLR Developer Network API key.
91+
92+
pvlib's CI utilizes a secret variable set to NLR_API_KEY
93+
(formerly NREL_API_KEY) to mitigate failures associated with
94+
using the default key of "DEMO_KEY". A user is capable of using
95+
their own key this way if desired however the default key should
96+
suffice for testing purposes.
9497
"""
9598
try:
9699
demo_key = os.environ["NLR_API_KEY"]
97100
except KeyError:
98-
try:
99-
demo_key = os.environ["NREL_API_KEY"]
100-
warnings.warn(
101-
"NREL_API_KEY is deprecated, use NLR_API_KEY instead",
102-
DeprecationWarning,
103-
stacklevel=2,
104-
)
105-
except KeyError:
106-
pytest.skip("requires NLR_API_KEY or NREL_API_KEY env var")
101+
warnings.warn(
102+
"WARNING: NLR_API_KEY (formerly NREL_API_KEY) environment "
103+
"variable not set! Using DEMO_KEY instead. "
104+
"Unexpected failures may occur."
105+
)
106+
demo_key = 'DEMO_KEY'
107107
return demo_key
108108

109109

110-
@pytest.fixture(scope="module")
111-
def nlr_api_key(nrel_api_key):
112-
"""Alias for nrel_api_key fixture."""
113-
return nrel_api_key
114-
115-
116110
try:
117111
# Attempt to load BSRN credentials used for testing pvlib.iotools.get_bsrn
118112
bsrn_username = os.environ["BSRN_FTP_USERNAME"]

tests/iotools/test_psm4.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pvlib.iotools import psm4
66
from ..conftest import (
7-
TESTS_DATA_DIR, RERUNS, RERUNS_DELAY, assert_index_equal, nrel_api_key
7+
TESTS_DATA_DIR, RERUNS, RERUNS_DELAY, assert_index_equal, nlr_api_key
88
)
99
import numpy as np
1010
import pandas as pd
@@ -54,10 +54,10 @@ def assert_psm4_equal(data, metadata, expected):
5454

5555
@pytest.mark.remote_data
5656
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
57-
def test_get_nsrdb_psm4_tmy(nrel_api_key):
57+
def test_get_nsrdb_psm4_tmy(nlr_api_key):
5858
"""test get_nsrdb_psm4_tmy with a TMY"""
5959
data, metadata = psm4.get_nsrdb_psm4_tmy(LATITUDE, LONGITUDE,
60-
nrel_api_key, PVLIB_EMAIL,
60+
nlr_api_key, PVLIB_EMAIL,
6161
year='tmy-2023',
6262
leap_day=False,
6363
map_variables=False)
@@ -67,10 +67,10 @@ def test_get_nsrdb_psm4_tmy(nrel_api_key):
6767

6868
@pytest.mark.remote_data
6969
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
70-
def test_get_nsrdb_psm4_full_disc(nrel_api_key):
70+
def test_get_nsrdb_psm4_full_disc(nlr_api_key):
7171
"""test get_nsrdb_psm4_full_disc with a single year"""
7272
data, metadata = psm4.get_nsrdb_psm4_full_disc(LATITUDE, LONGITUDE,
73-
nrel_api_key, PVLIB_EMAIL,
73+
nlr_api_key, PVLIB_EMAIL,
7474
year='2023',
7575
leap_day=False,
7676
map_variables=False)
@@ -80,10 +80,10 @@ def test_get_nsrdb_psm4_full_disc(nrel_api_key):
8080

8181
@pytest.mark.remote_data
8282
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
83-
def test_get_nsrdb_psm4_conus_singleyear(nrel_api_key):
83+
def test_get_nsrdb_psm4_conus_singleyear(nlr_api_key):
8484
"""test get_nsrdb_psm4_conus with a single year"""
8585
data, metadata = psm4.get_nsrdb_psm4_aggregated(LATITUDE, LONGITUDE,
86-
nrel_api_key,
86+
nlr_api_key,
8787
PVLIB_EMAIL,
8888
year='2023',
8989
leap_day=False,
@@ -95,10 +95,10 @@ def test_get_nsrdb_psm4_conus_singleyear(nrel_api_key):
9595

9696
@pytest.mark.remote_data
9797
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
98-
def test_get_nsrdb_psm4_conus_5min(nrel_api_key):
98+
def test_get_nsrdb_psm4_conus_5min(nlr_api_key):
9999
"""test get_nsrdb_psm4_conus for 5-minute data"""
100100
data, metadata = psm4.get_nsrdb_psm4_conus(LATITUDE, LONGITUDE,
101-
nrel_api_key, PVLIB_EMAIL,
101+
nlr_api_key, PVLIB_EMAIL,
102102
year='2023', time_step=5,
103103
leap_day=False,
104104
map_variables=False)
@@ -110,10 +110,10 @@ def test_get_nsrdb_psm4_conus_5min(nrel_api_key):
110110

111111
@pytest.mark.remote_data
112112
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
113-
def test_get_nsrdb_psm4_aggregated_check_leap_day(nrel_api_key):
113+
def test_get_nsrdb_psm4_aggregated_check_leap_day(nlr_api_key):
114114
"""test get_nsrdb_psm4_aggregated for leap day"""
115115
data_2012, _ = psm4.get_nsrdb_psm4_aggregated(LATITUDE, LONGITUDE,
116-
nrel_api_key, PVLIB_EMAIL,
116+
nlr_api_key, PVLIB_EMAIL,
117117
year="2012", time_step=60,
118118
leap_day=True,
119119
map_variables=False)
@@ -122,9 +122,9 @@ def test_get_nsrdb_psm4_aggregated_check_leap_day(nrel_api_key):
122122

123123
@pytest.mark.parametrize('latitude, longitude, api_key, year, time_step',
124124
[(LATITUDE, LONGITUDE, 'BAD', '2023', 60),
125-
(51, -5, nrel_api_key, '2023', 60),
126-
(LATITUDE, LONGITUDE, nrel_api_key, 'bad', 60),
127-
(LATITUDE, LONGITUDE, nrel_api_key, '2023', 15),
125+
(51, -5, nlr_api_key, '2023', 60),
126+
(LATITUDE, LONGITUDE, nlr_api_key, 'bad', 60),
127+
(LATITUDE, LONGITUDE, nlr_api_key, '2023', 15),
128128
])
129129
@pytest.mark.remote_data
130130
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
@@ -187,11 +187,11 @@ def test_read_nsrdb_psm4_map_variables():
187187

188188
@pytest.mark.remote_data
189189
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
190-
def test_get_nsrdb_psm4_aggregated_parameter_mapping(nrel_api_key):
190+
def test_get_nsrdb_psm4_aggregated_parameter_mapping(nlr_api_key):
191191
"""Test that pvlib names can be passed in as parameters and get correctly
192192
reverse mapped to psm4 names"""
193193
data, meta = psm4.get_nsrdb_psm4_aggregated(
194-
LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, year='2019',
194+
LATITUDE, LONGITUDE, nlr_api_key, PVLIB_EMAIL, year='2019',
195195
time_step=60, parameters=['ghi', 'wind_speed'], leap_day=False,
196196
map_variables=True)
197197
# Check that columns are in the correct order (GH1647)

0 commit comments

Comments
 (0)