Skip to content

Commit 94834a0

Browse files
committed
deprecate parse_bsrn
1 parent 389e3d1 commit 94834a0

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

pvlib/iotools/bsrn.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import warnings
99
import io
1010
import os
11+
from functools import partial
12+
13+
from pvlib.tools import _file_context_manager
14+
from pvlib._deprecation import deprecated
1115

1216
BSRN_FTP_URL = "ftp.bsrn.awi.de"
1317

@@ -136,7 +140,7 @@ def get_bsrn(station, start, end, username, password,
136140
137141
See Also
138142
--------
139-
pvlib.iotools.read_bsrn, pvlib.iotools.parse_bsrn
143+
pvlib.iotools.read_bsrn
140144
141145
References
142146
----------
@@ -191,7 +195,7 @@ def get_bsrn(station, start, end, username, password,
191195
bio.seek(0) # reset buffer to start of file
192196
gzip_file = io.TextIOWrapper(gzip.GzipFile(fileobj=bio),
193197
encoding='latin1')
194-
dfi, metadata = parse_bsrn(gzip_file, logical_records)
198+
dfi, metadata = _parse_bsrn(gzip_file, logical_records)
195199
dfs.append(dfi)
196200
# FTP client raises an error if the file does not exist on server
197201
except ftplib.error_perm as e:
@@ -217,7 +221,7 @@ def get_bsrn(station, start, end, username, password,
217221
return data, metadata
218222

219223

220-
def parse_bsrn(fbuf, logical_records=('0100',)):
224+
def _parse_bsrn(fbuf, logical_records=('0100',)):
221225
"""
222226
Parse a file-like buffer of a BSRN station-to-archive file.
223227
@@ -382,7 +386,7 @@ def read_bsrn(filename, logical_records=('0100',)):
382386
Parameters
383387
----------
384388
filename: str or path-like
385-
Name or path of a BSRN station-to-archive data file
389+
Name, path, or in-memory buffer of a BSRN station-to-archive data file
386390
logical_records: list or tuple, default: ('0100',)
387391
List of the logical records (LR) to parse. Options include: '0100',
388392
'0300', and '0500'.
@@ -439,7 +443,7 @@ def read_bsrn(filename, logical_records=('0100',)):
439443
440444
See Also
441445
--------
442-
pvlib.iotools.parse_bsrn, pvlib.iotools.get_bsrn
446+
pvlib.iotools.get_bsrn
443447
444448
References
445449
----------
@@ -455,9 +459,13 @@ def read_bsrn(filename, logical_records=('0100',)):
455459
<https://bsrn.awi.de/data/conditions-of-data-release/>`_
456460
""" # noqa: E501
457461
if str(filename).endswith('.gz'): # check if file is a gzipped (.gz) file
458-
open_func, mode = gzip.open, 'rt'
462+
open_func = partial(gzip.open, mode='rt')
459463
else:
460-
open_func, mode = open, 'r'
461-
with open_func(filename, mode) as f:
462-
content = parse_bsrn(f, logical_records)
464+
open_func = _file_context_manager(filename, mode='r')
465+
with open_func(filename) as f:
466+
content = _parse_bsrn(f, logical_records)
463467
return content
468+
469+
470+
parse_bsrn = deprecated(since="0.13.0", name="parse_bsrn",
471+
alternative="read_bsrn")(read_bsrn)

0 commit comments

Comments
 (0)