Skip to content
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

Remove pvgis_tmy outputformat='basic' #2416

Open
wants to merge 6 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
34 changes: 34 additions & 0 deletions docs/sphinx/source/whatsnew/v0.13.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. _whatsnew_01300:


v0.13.0 (June XX, 2025)
------------------------

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

Bug fixes
~~~~~~~~~


Enhancements
~~~~~~~~~~~~


Documentation
~~~~~~~~~~~~~


Testing
~~~~~~~


Maintenance
~~~~~~~~~~~


Contributors
~~~~~~~~~~~~
* Adam R. Jensen (:ghuser:`AdamRJensen`)
89 changes: 42 additions & 47 deletions pvlib/iotools/pvgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def read_pvgis_hourly(filename, pvgis_format=None, map_variables=True):
return _parse_pvgis_hourly_json(src, map_variables=map_variables)

# CSV: use _parse_pvgis_hourly_csv()
if outputformat == 'csv':
elif outputformat == 'csv':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary, this code can't be reached if outputformat is 'json'

try:
pvgis_data = _parse_pvgis_hourly_csv(
filename, map_variables=map_variables)
Expand All @@ -383,11 +383,17 @@ def read_pvgis_hourly(filename, pvgis_format=None, map_variables=True):
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)
elif outputformat == 'basic':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this condition and these changes should be moved to get_pvgis_tmy() instead of here in read_pvgis_hourly() which does not accept basic as input to the pvgis_format argument

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', 'json']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this up to the top where outputformat is defined to raise an exception asap.

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 +435,7 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
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 +467,11 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
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 +522,16 @@ def get_pvgis_tmy(latitude, longitude, outputformat='json', usehorizon=True,
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
# raise exception if pvgis format isn't in ['csv', 'json', 'epw']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary, this line will never be reached because pvgis will return 400 BAD REQUEST if the outputformat isn't one of the options specified by the API

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
err_msg = (
"pvgis format '{:s}' was unknown, must be either 'json', 'csv', or"
" 'epw'.").format(outputformat)
raise ValueError(err_msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the condition for 'basic' and changes from read_pvgis_hourly() to here:

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


if map_variables:
data = data.rename(columns=VARIABLE_MAP)
Expand Down Expand Up @@ -590,14 +595,6 @@ def _parse_pvgis_tmy_csv(src):
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 +607,9 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
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 +620,18 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
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 +647,7 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
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 +657,7 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
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 +671,25 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=True):
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']
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