Skip to content

Commit ae44a1d

Browse files
committed
deprecate parse_epw
1 parent 389e3d1 commit ae44a1d

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

pvlib/iotools/epw.py

Lines changed: 14 additions & 10 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,18 @@ 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)
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)
235235

236236

237237
return data, meta
238238

239239

240-
def parse_epw(csvdata, coerce_year=None):
240+
def _parse_epw(csvdata, coerce_year=None):
241241
"""
242242
Given a file-like buffer with data in Energy Plus Weather (EPW) format,
243243
parse the data into a dataframe.
@@ -310,3 +310,7 @@ def parse_epw(csvdata, coerce_year=None):
310310
data.index = idx
311311

312312
return data, meta
313+
314+
315+
parse_epw = deprecated(since="0.13.0", name="parse_epw",
316+
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

0 commit comments

Comments
 (0)