66from urllib .request import urlopen , Request
77import pandas as pd
88
9+ from pvlib .tools import _file_context_manager
10+ from pvlib ._deprecation import deprecated
11+
912
1013def 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 )
0 commit comments