Skip to content

Commit 23acb14

Browse files
committed
Raise if no parameters provided to retrieve_sam() (#770)
Instead of showing up a dialog.
1 parent 0a14b27 commit 23acb14

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ compatibility notes.
1010
**Python 2.7 support ended on June 1, 2019.** (:issue:`501`)
1111
**Minimum numpy version is now 1.10.4. Minimum pandas version is now 0.18.1.**
1212

13+
API Changes
14+
~~~~~~~~~~~
15+
* Calling :py:func:`pvlib.pvsystem.retrieve_sam` with no parameters will raise
16+
an exception instead of showing up a dialog.
17+
1318
Enhancements
1419
~~~~~~~~~~~~
1520
* Created two new incidence angle modifier functions: :py:func:`pvlib.pvsystem.iam_martin_ruiz`
@@ -38,3 +43,4 @@ Contributors
3843
* Oscar Dowson (:ghuser:`odow`)
3944
* Anton Driesse (:ghuser:`adriesse`)
4045
* Alexander Morgan (:ghuser:`alexandermorgan`)
46+
* Miguel Sánchez de León Peque (:ghuser:`Peque`)

pvlib/pvsystem.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,16 +1717,18 @@ def retrieve_sam(name=None, path=None):
17171717
path : None or string, default None
17181718
Path to the SAM file. May also be a URL.
17191719
1720-
If both name and path are None, a dialogue will open allowing the
1721-
user to select a file.
1722-
17231720
Returns
17241721
-------
17251722
samfile : DataFrame
17261723
A DataFrame containing all the elements of the desired database.
17271724
Each column represents a module or inverter, and a specific
17281725
dataset can be retrieved by the command
17291726
1727+
Raises
1728+
------
1729+
ValueError
1730+
If no name or path is provided.
1731+
17301732
Notes
17311733
-----
17321734
Files available at https://sam.nrel.gov/sites/default/files/
@@ -1781,11 +1783,7 @@ def retrieve_sam(name=None, path=None):
17811783
else:
17821784
csvdata = path
17831785
elif name is None and path is None:
1784-
import tkinter
1785-
from tkinter.filedialog import askopenfilename
1786-
1787-
tkinter.Tk().withdraw()
1788-
csvdata = askopenfilename()
1786+
raise ValueError("A name or path must be provided!")
17891787

17901788
return _parse_raw_sam_df(csvdata)
17911789

pvlib/test/test_pvsystem.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ def pvsyst_module_params():
274274
return module_parameters
275275

276276

277+
def test_retrieve_sam_raise_no_parameters():
278+
"""
279+
Raise an exception if no parameters are provided to `retrieve_sam()`.
280+
"""
281+
with pytest.raises(ValueError) as error:
282+
pvsystem.retrieve_sam()
283+
assert 'A name or path must be provided!' == str(error.value)
284+
285+
277286
def test_sapm(sapm_module_params):
278287

279288
times = pd.date_range(start='2015-01-01', periods=5, freq='12H')

0 commit comments

Comments
 (0)