Skip to content

Commit 5be6b7f

Browse files
authored
Remove pvgis_tmy outputformat='basic' (#2416)
* Remove basic option from PVGIS_TMY * Remove pvgis_tmy outputformat='basic' option * Add whatsnew * Delete tmy_45.000_8.000_2005_2023.txt * Add basic warning * Fix linter * Implement changes from review * Delete v0.13.0.rst * Update v0.12.1.rst * Add bad/basic outputformat tests * Delete tmy_45.000_8.000_2005_2023.txt * Correct tests * Simplify tests * Update read_pvgis_tmy description * Remove raise exception comment
1 parent 7b7e3c7 commit 5be6b7f

File tree

4 files changed

+54
-8842
lines changed

4 files changed

+54
-8842
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Breaking Changes
1111
following the iotools convention instead of ``(data,inputs,meta)``.
1212
The ``inputs`` dictionary is now included in ``meta``, which
1313
has changed structure to accommodate it. (:pull:`2462`)
14+
* Remove ``outputformat='basic'`` option in :py:func:`~pvlib.iotools.get_pvgis_tmy`.
15+
(:pull:`2416`)
1416

1517
Deprecations
1618
~~~~~~~~~~~~

pvlib/iotools/pvgis.py

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def read_pvgis_hourly(filename, pvgis_format=None, map_variables=True):
387387
return _parse_pvgis_hourly_json(src, map_variables=map_variables)
388388

389389
# CSV: use _parse_pvgis_hourly_csv()
390-
if outputformat == 'csv':
390+
elif outputformat == 'csv':
391391
try:
392392
pvgis_data = _parse_pvgis_hourly_csv(
393393
filename, map_variables=map_variables)
@@ -397,11 +397,12 @@ def read_pvgis_hourly(filename, pvgis_format=None, map_variables=True):
397397
fbuf, map_variables=map_variables)
398398
return pvgis_data
399399

400-
# raise exception if pvgis format isn't in ['csv', 'json']
401-
err_msg = (
402-
"pvgis format '{:s}' was unknown, must be either 'json' or 'csv'")\
403-
.format(outputformat)
404-
raise ValueError(err_msg)
400+
else:
401+
# raise exception if pvgis format isn't in ['csv', 'json']
402+
err_msg = (
403+
"pvgis format '{:s}' was unknown, must be either 'json' or 'csv'")\
404+
.format(outputformat)
405+
raise ValueError(err_msg)
405406

406407

407408
def _coerce_and_roll_tmy(tmy_data, tz, year):
@@ -446,7 +447,7 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
446447
longitude : float
447448
Longitude in degrees east
448449
outputformat : str, default 'json'
449-
Must be in ``['csv', 'basic', 'epw', 'json']``. See PVGIS TMY tool
450+
Must be in ``['csv', 'epw', 'json']``. See PVGIS TMY tool
450451
documentation [2]_ for more info.
451452
usehorizon : bool, default True
452453
include effects of horizon
@@ -478,11 +479,11 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
478479
data : pandas.DataFrame
479480
the weather data
480481
months_selected : list
481-
TMY year for each month, ``None`` for basic and EPW
482+
TMY year for each month, ``None`` for EPW
482483
inputs : dict
483-
the inputs, ``None`` for basic and EPW
484+
the inputs, ``None`` for EPW
484485
metadata : list or dict
485-
file metadata, ``None`` for basic
486+
file metadata
486487
487488
Raises
488489
------
@@ -533,17 +534,14 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
533534
elif outputformat == 'csv':
534535
with io.BytesIO(res.content) as src:
535536
data, months_selected, inputs, meta = _parse_pvgis_tmy_csv(src)
536-
elif outputformat == 'basic':
537-
with io.BytesIO(res.content) as src:
538-
data, months_selected, inputs, meta = _parse_pvgis_tmy_basic(src)
539537
elif outputformat == 'epw':
540538
with io.StringIO(res.content.decode('utf-8')) as src:
541539
data, meta = parse_epw(src)
542540
months_selected, inputs = None, None
543-
else:
544-
# this line is never reached because if outputformat is not valid then
545-
# the response is HTTP/1.1 400 BAD REQUEST which is handled earlier
546-
pass
541+
elif outputformat == 'basic':
542+
err_msg = ("outputformat='basic' is no longer supported by pvlib, "
543+
"please use outputformat='csv' instead.")
544+
raise ValueError(err_msg)
547545

548546
if map_variables:
549547
data = data.rename(columns=VARIABLE_MAP)
@@ -607,17 +605,9 @@ def _parse_pvgis_tmy_csv(src):
607605
return data, months_selected, inputs, meta
608606

609607

610-
def _parse_pvgis_tmy_basic(src):
611-
data = pd.read_csv(src)
612-
data.index = pd.to_datetime(
613-
data['time(UTC)'], format='%Y%m%d:%H%M', utc=True)
614-
data = data.drop('time(UTC)', axis=1)
615-
return data, None, None, None
616-
617-
618608
def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
619609
"""
620-
Read a file downloaded from PVGIS.
610+
Read a TMY file downloaded from PVGIS.
621611
622612
Parameters
623613
----------
@@ -627,11 +617,9 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
627617
Format of PVGIS file or buffer. Equivalent to the ``outputformat``
628618
parameter in the PVGIS TMY API. If ``filename`` is a file and
629619
``pvgis_format`` is not specified then the file extension will be used
630-
to determine the PVGIS format to parse. For PVGIS files from the API
631-
with ``outputformat='basic'``, please set ``pvgis_format`` to
632-
``'basic'``.
620+
to determine the PVGIS format to parse.
633621
If ``filename`` is a buffer, then ``pvgis_format`` is required and must
634-
be in ``['csv', 'epw', 'json', 'basic']``.
622+
be in ``['csv', 'epw', 'json']``.
635623
map_variables: bool, default True
636624
When true, renames columns of the Dataframe to pvlib variable names
637625
where applicable. See variable :const:`VARIABLE_MAP`.
@@ -642,18 +630,18 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
642630
data : pandas.DataFrame
643631
the weather data
644632
months_selected : list
645-
TMY year for each month, ``None`` for basic and EPW
633+
TMY year for each month, ``None`` for EPW
646634
inputs : dict
647-
the inputs, ``None`` for basic and EPW
635+
the inputs, ``None`` for EPW
648636
metadata : list or dict
649-
file metadata, ``None`` for basic
637+
file metadata
650638
651639
Raises
652640
------
653641
ValueError
654642
if ``pvgis_format`` is not specified and the file extension is neither
655643
``.csv``, ``.json``, nor ``.epw``, or if ``pvgis_format`` is provided
656-
as input but isn't in ``['csv', 'epw', 'json', 'basic']``
644+
as input but isn't in ``['csv', 'epw', 'json']``
657645
TypeError
658646
if ``pvgis_format`` is not specified and ``filename`` is a buffer
659647
@@ -669,8 +657,7 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
669657
outputformat = Path(filename).suffix[1:].lower()
670658
else:
671659
outputformat = pvgis_format
672-
# parse the pvgis file based on the output format, either 'epw', 'json',
673-
# 'csv', or 'basic'
660+
# parse pvgis file based on outputformat, either 'epw', 'json', or 'csv'
674661

675662
# EPW: use the EPW parser from the pvlib.iotools epw.py module
676663
if outputformat == 'epw':
@@ -680,7 +667,7 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
680667
data, meta = read_epw(filename)
681668
months_selected, inputs = None, None
682669

683-
# NOTE: json, csv, and basic output formats have parsers defined as private
670+
# NOTE: json and csv output formats have parsers defined as private
684671
# functions in this module
685672

686673
# JSON: use Python built-in json module to convert file contents to a
@@ -694,24 +681,25 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
694681
src = json.load(fbuf)
695682
data, months_selected, inputs, meta = _parse_pvgis_tmy_json(src)
696683

697-
# CSV or basic: use the correct parser from this module
698-
# eg: _parse_pvgis_tmy_csv() or _parse_pvgist_tmy_basic()
699-
elif outputformat in ['csv', 'basic']:
700-
# get the correct parser function for this output format from globals()
701-
pvgis_parser = globals()['_parse_pvgis_tmy_{:s}'.format(outputformat)]
702-
# NOTE: pvgis_parse() is a pvgis parser function from this module,
703-
# either _parse_pvgis_tmy_csv() or _parse_pvgist_tmy_basic()
684+
elif outputformat == 'csv':
704685
try:
705-
data, months_selected, inputs, meta = pvgis_parser(filename)
686+
data, months_selected, inputs, meta = \
687+
_parse_pvgis_tmy_csv(filename)
706688
except AttributeError: # str/path has no .read() attribute
707689
with open(str(filename), 'rb') as fbuf:
708-
data, months_selected, inputs, meta = pvgis_parser(fbuf)
690+
data, months_selected, inputs, meta = \
691+
_parse_pvgis_tmy_csv(fbuf)
692+
693+
elif outputformat == 'basic':
694+
err_msg = "outputformat='basic' is no longer supported, please use " \
695+
"outputformat='csv' instead."
696+
raise ValueError(err_msg)
709697

710698
else:
711-
# raise exception if pvgis format isn't in ['csv','basic','epw','json']
699+
# raise exception if pvgis format isn't in ['csv','epw','json']
712700
err_msg = (
713-
"pvgis format '{:s}' was unknown, must be either 'epw', 'json', "
714-
"'csv', or 'basic'").format(outputformat)
701+
"pvgis format '{:s}' was unknown, must be either 'json', 'csv',"
702+
"or 'epw'").format(outputformat)
715703
raise ValueError(err_msg)
716704

717705
if map_variables:

0 commit comments

Comments
 (0)