Skip to content

Remove pvgis_tmy outputformat='basic' #2416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/sphinx/source/whatsnew/v0.12.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ v0.12.1 (XXXX, 2025)

Breaking Changes
~~~~~~~~~~~~~~~~

* Remove ``outputformat='basic'`` option in :py:func:`~pvlib.iotools.get_pvgis_tmy`.
(:pull:`2416`)

Bug fixes
~~~~~~~~~
Expand Down
85 changes: 37 additions & 48 deletions pvlib/iotools/pvgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
return _parse_pvgis_hourly_json(src, map_variables=map_variables)

# CSV: use _parse_pvgis_hourly_csv()
if outputformat == 'csv':
elif outputformat == 'csv':
try:
pvgis_data = _parse_pvgis_hourly_csv(
filename, map_variables=map_variables)
Expand All @@ -383,11 +383,12 @@
fbuf, map_variables=map_variables)
return pvgis_data

# raise exception if pvgis format isn't in ['csv', 'json']
err_msg = (
"pvgis format '{:s}' was unknown, must be either 'json' or 'csv'")\
.format(outputformat)
raise ValueError(err_msg)
else:
# raise exception if pvgis format isn't in ['csv', 'json']
err_msg = (
"pvgis format '{:s}' was unknown, must be either 'json' or 'csv'")\
.format(outputformat)
raise ValueError(err_msg)


def _coerce_and_roll_tmy(tmy_data, tz, year):
Expand Down Expand Up @@ -429,7 +430,7 @@
longitude : float
Longitude in degrees east
outputformat : str, default 'json'
Must be in ``['csv', 'basic', 'epw', 'json']``. See PVGIS TMY tool
Must be in ``['csv', 'epw', 'json']``. See PVGIS TMY tool
documentation [2]_ for more info.
usehorizon : bool, default True
include effects of horizon
Expand Down Expand Up @@ -461,11 +462,11 @@
data : pandas.DataFrame
the weather data
months_selected : list
TMY year for each month, ``None`` for basic and EPW
TMY year for each month, ``None`` for EPW
inputs : dict
the inputs, ``None`` for basic and EPW
the inputs, ``None`` for EPW
metadata : list or dict
file metadata, ``None`` for basic
file metadata

Raises
------
Expand Down Expand Up @@ -516,17 +517,15 @@
elif outputformat == 'csv':
with io.BytesIO(res.content) as src:
data, months_selected, inputs, meta = _parse_pvgis_tmy_csv(src)
elif outputformat == 'basic':
with io.BytesIO(res.content) as src:
data, months_selected, inputs, meta = _parse_pvgis_tmy_basic(src)
elif outputformat == 'epw':
with io.StringIO(res.content.decode('utf-8')) as src:
data, meta = parse_epw(src)
months_selected, inputs = None, None
else:
# this line is never reached because if outputformat is not valid then
# the response is HTTP/1.1 400 BAD REQUEST which is handled earlier
pass
# raise exception if pvgis format isn't in ['csv', 'json', 'epw']
elif outputformat == 'basic':
err_msg = ("outputformat='basic' is no longer supported by pvlib, "
"please use outputformat='csv' instead.")
raise ValueError(err_msg)

if map_variables:
data = data.rename(columns=VARIABLE_MAP)
Expand Down Expand Up @@ -590,14 +589,6 @@
return data, months_selected, inputs, meta


def _parse_pvgis_tmy_basic(src):
data = pd.read_csv(src)
data.index = pd.to_datetime(
data['time(UTC)'], format='%Y%m%d:%H%M', utc=True)
data = data.drop('time(UTC)', axis=1)
return data, None, None, None


def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
"""
Read a file downloaded from PVGIS.
Expand All @@ -610,11 +601,9 @@
Format of PVGIS file or buffer. Equivalent to the ``outputformat``
parameter in the PVGIS TMY API. If ``filename`` is a file and
``pvgis_format`` is not specified then the file extension will be used
to determine the PVGIS format to parse. For PVGIS files from the API
with ``outputformat='basic'``, please set ``pvgis_format`` to
``'basic'``.
to determine the PVGIS format to parse.
If ``filename`` is a buffer, then ``pvgis_format`` is required and must
be in ``['csv', 'epw', 'json', 'basic']``.
be in ``['csv', 'epw', 'json']``.
map_variables: bool, default True
When true, renames columns of the Dataframe to pvlib variable names
where applicable. See variable :const:`VARIABLE_MAP`.
Expand All @@ -625,18 +614,18 @@
data : pandas.DataFrame
the weather data
months_selected : list
TMY year for each month, ``None`` for basic and EPW
TMY year for each month, ``None`` for EPW
inputs : dict
the inputs, ``None`` for basic and EPW
the inputs, ``None`` for EPW
metadata : list or dict
file metadata, ``None`` for basic
file metadata

Raises
------
ValueError
if ``pvgis_format`` is not specified and the file extension is neither
``.csv``, ``.json``, nor ``.epw``, or if ``pvgis_format`` is provided
as input but isn't in ``['csv', 'epw', 'json', 'basic']``
as input but isn't in ``['csv', 'epw', 'json']``
TypeError
if ``pvgis_format`` is not specified and ``filename`` is a buffer

Expand All @@ -652,8 +641,7 @@
outputformat = Path(filename).suffix[1:].lower()
else:
outputformat = pvgis_format
# parse the pvgis file based on the output format, either 'epw', 'json',
# 'csv', or 'basic'
# parse pvgis file based on outputformat, either 'epw', 'json', or 'csv'

# EPW: use the EPW parser from the pvlib.iotools epw.py module
if outputformat == 'epw':
Expand All @@ -663,7 +651,7 @@
data, meta = read_epw(filename)
months_selected, inputs = None, None

# NOTE: json, csv, and basic output formats have parsers defined as private
# NOTE: json and csv output formats have parsers defined as private
# functions in this module

# JSON: use Python built-in json module to convert file contents to a
Expand All @@ -677,24 +665,25 @@
src = json.load(fbuf)
data, months_selected, inputs, meta = _parse_pvgis_tmy_json(src)

# CSV or basic: use the correct parser from this module
# eg: _parse_pvgis_tmy_csv() or _parse_pvgist_tmy_basic()
elif outputformat in ['csv', 'basic']:
# get the correct parser function for this output format from globals()
pvgis_parser = globals()['_parse_pvgis_tmy_{:s}'.format(outputformat)]
# NOTE: pvgis_parse() is a pvgis parser function from this module,
# either _parse_pvgis_tmy_csv() or _parse_pvgist_tmy_basic()
elif outputformat == 'csv':
try:
data, months_selected, inputs, meta = pvgis_parser(filename)
data, months_selected, inputs, meta = \
_parse_pvgis_tmy_csv(filename)
except AttributeError: # str/path has no .read() attribute
with open(str(filename), 'rb') as fbuf:
data, months_selected, inputs, meta = pvgis_parser(fbuf)
data, months_selected, inputs, meta = \
_parse_pvgis_tmy_csv(fbuf)

elif outputformat == 'basic':
err_msg = "outputformat='basic' is no longer supported, please use " \
"outputformat='csv' instead."
raise ValueError(err_msg)

else:
# raise exception if pvgis format isn't in ['csv','basic','epw','json']
# raise exception if pvgis format isn't in ['csv','epw','json']

Check warning on line 683 in pvlib/iotools/pvgis.py

View check run for this annotation

Codecov / codecov/patch

pvlib/iotools/pvgis.py#L683

Added line #L683 was not covered by tests
err_msg = (
"pvgis format '{:s}' was unknown, must be either 'epw', 'json', "
"'csv', or 'basic'").format(outputformat)
"pvgis format '{:s}' was unknown, must be either 'json', 'csv',"
"or 'epw'").format(outputformat)
raise ValueError(err_msg)

if map_variables:
Expand Down
Loading
Loading