-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Changes from all commits
c83ecc7
33e15a5
ff7de82
de2712b
e7d80e3
28e7d58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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`) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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': | ||
try: | ||
pvgis_data = _parse_pvgis_hourly_csv( | ||
filename, map_variables=map_variables) | ||
|
@@ -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': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this condition and these changes should be moved to |
||
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'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this up to the top where |
||
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): | ||
|
@@ -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 | ||
|
@@ -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 | ||
------ | ||
|
@@ -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) | ||
AdamRJensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move the condition for
|
||
|
||
if map_variables: | ||
data = data.rename(columns=VARIABLE_MAP) | ||
|
@@ -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. | ||
|
@@ -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`. | ||
|
@@ -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 | ||
|
||
|
@@ -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': | ||
|
@@ -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 | ||
|
@@ -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) | ||
AdamRJensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise ValueError(err_msg) | ||
|
||
if map_variables: | ||
|
There was a problem hiding this comment.
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'