Skip to content

Commit 49528aa

Browse files
Deprecate parse_epw (#2467)
* deprecate parse_epw * tests * whatsnew * lint * PR number in whatsnew --------- Co-authored-by: Adam R. Jensen <39184289+AdamRJensen@users.noreply.github.com>
1 parent 3bc67a2 commit 49528aa

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Breaking Changes
1717
Deprecations
1818
~~~~~~~~~~~~
1919
* The following ``parse_`` functions in :py:mod:`pvlib.iotools` are deprecated,
20-
with the corresponding ``read_`` functions taking their place: (:issue:`2444`, :pull:`2458`, :pull:`2466`)
20+
with the corresponding ``read_`` functions taking their place: (:issue:`2444`, :pull:`2458`,
21+
:pull:`2467`, :pull:`2466`)
2122

23+
- :py:func:`~pvlib.iotools.parse_epw`
2224
- :py:func:`~pvlib.iotools.parse_psm3`
2325
- :py:func:`~pvlib.iotools.parse_cams`
2426
- :py:func:`~pvlib.iotools.parse_bsrn`

pvlib/iotools/epw.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from urllib.request import urlopen, Request
77
import pandas as pd
88

9+
from pvlib.tools import _file_context_manager
10+
from pvlib._deprecation import deprecated
11+
912

1013
def read_epw(filename, coerce_year=None):
1114
r'''
@@ -23,7 +26,8 @@ def read_epw(filename, coerce_year=None):
2326
Parameters
2427
----------
2528
filename : String
26-
Can be a relative file path, absolute file path, or url.
29+
Can be a relative file path, absolute file path, url, or in-memory
30+
file buffer.
2731
2832
coerce_year : int, optional
2933
If supplied, the year of the data will be set to this value. This can
@@ -43,10 +47,6 @@ def read_epw(filename, coerce_year=None):
4347
metadata : dict
4448
The site metadata available in the file.
4549
46-
See Also
47-
--------
48-
pvlib.iotools.parse_epw
49-
5050
Notes
5151
-----
5252
@@ -226,18 +226,17 @@ def read_epw(filename, coerce_year=None):
226226
'Safari/537.36')})
227227
response = urlopen(request)
228228
with io.StringIO(response.read().decode(errors='ignore')) as csvdata:
229-
data, meta = parse_epw(csvdata, coerce_year)
229+
data, meta = _parse_epw(csvdata, coerce_year)
230230

231231
else:
232-
# Assume it's accessible via the file system
233-
with open(str(filename), 'r') as csvdata:
234-
data, meta = parse_epw(csvdata, coerce_year)
235-
232+
# Assume it's a buffer or accessible via the file system
233+
with _file_context_manager(filename, 'r') as csvdata:
234+
data, meta = _parse_epw(csvdata, coerce_year)
236235

237236
return data, meta
238237

239238

240-
def parse_epw(csvdata, coerce_year=None):
239+
def _parse_epw(csvdata, coerce_year=None):
241240
"""
242241
Given a file-like buffer with data in Energy Plus Weather (EPW) format,
243242
parse the data into a dataframe.
@@ -310,3 +309,7 @@ def parse_epw(csvdata, coerce_year=None):
310309
data.index = idx
311310

312311
return data, meta
312+
313+
314+
parse_epw = deprecated(since="0.13.0", name="parse_epw",
315+
alternative="read_epw")(read_epw)

pvlib/iotools/pvgis.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import numpy as np
2222
import pandas as pd
2323
import pytz
24-
from pvlib.iotools import read_epw, parse_epw
24+
from pvlib.iotools import read_epw
2525

2626
URL = 'https://re.jrc.ec.europa.eu/api/'
2727

@@ -536,7 +536,7 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
536536
data, months_selected, inputs, meta = _parse_pvgis_tmy_csv(src)
537537
elif outputformat == 'epw':
538538
with io.StringIO(res.content.decode('utf-8')) as src:
539-
data, meta = parse_epw(src)
539+
data, meta = read_epw(src)
540540
months_selected, inputs = None, None
541541
elif outputformat == 'basic':
542542
err_msg = ("outputformat='basic' is no longer supported by pvlib, "
@@ -661,10 +661,7 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
661661

662662
# EPW: use the EPW parser from the pvlib.iotools epw.py module
663663
if outputformat == 'epw':
664-
try:
665-
data, meta = parse_epw(filename)
666-
except AttributeError: # str/path has no .read() attribute
667-
data, meta = read_epw(filename)
664+
data, meta = read_epw(filename)
668665
months_selected, inputs = None, None
669666

670667
# NOTE: json and csv output formats have parsers defined as private

tests/iotools/test_epw.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,33 @@
33
from pvlib.iotools import epw
44
from tests.conftest import TESTS_DATA_DIR, RERUNS, RERUNS_DELAY
55

6+
from pvlib._deprecation import pvlibDeprecationWarning
7+
68
epw_testfile = TESTS_DATA_DIR / 'NLD_Amsterdam062400_IWEC.epw'
79

810

911
def test_read_epw():
10-
epw.read_epw(epw_testfile)
12+
df, meta = epw.read_epw(epw_testfile)
13+
assert len(df) == 8760
14+
assert 'ghi' in df.columns
15+
assert meta['latitude'] == 52.3
16+
17+
18+
def test_read_epw_buffer():
19+
with open(epw_testfile, 'r') as f:
20+
df, meta = epw.read_epw(f)
21+
assert len(df) == 8760
22+
assert 'ghi' in df.columns
23+
assert meta['latitude'] == 52.3
24+
25+
26+
def test_parse_epw_deprecated():
27+
with pytest.warns(pvlibDeprecationWarning, match='Use read_epw instead'):
28+
with open(epw_testfile, 'r') as f:
29+
df, meta = epw.parse_epw(f)
30+
assert len(df) == 8760
31+
assert 'ghi' in df.columns
32+
assert meta['latitude'] == 52.3
1133

1234

1335
@pytest.mark.remote_data

0 commit comments

Comments
 (0)