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

Conversation

AdamRJensen
Copy link
Member

@AdamRJensen AdamRJensen commented Mar 21, 2025

  • I am familiar with the contributing guidelines
  • Tests added
  • Updates entries in docs/sphinx/source/reference for API changes.
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

PVGIS offers multiple output formats. For hourly data the file formats ['csv', 'json', 'basic'] are available, whereas for TMY data file format of ['csv', 'json', 'epw', 'basic'] are available.

I suggest that we drop support for the 'basic' output format as there is no point to it; the file type is the same as the csv option but without any header or metadata. For this reason, the file option is also not available on the pvgis web interface and is already not supported by pvlib's pvgis_hourly functions.

The motivation is to reduce the maintenance burden, as dropping support for this file format reduces the code complexity significantly without any drawbacks for users. I'm currently planning more changes to the pvgis functions, but would like this change to be merged first. The planned changes mostly involve changing the outputs to be (data,meta) to be consistent with the rest of the iotools.

@AdamRJensen AdamRJensen added the io label Mar 21, 2025
Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

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

I think there is no technical barrier to deprecating outputformat='basic' for a while before removing it altogether. However, I bet basic is hardly used, so for the sake of expediency and not taxing @AdamRJensen's patience, I am okay with no deprecation period here, although I grumble nonetheless.

I did not do a thorough review, but these changes seem okay to me (assuming nobody objects to removing basic in the first place). A couple small notes below.

@AdamRJensen
Copy link
Member Author

I think there is no technical barrier to deprecating outputformat='basic' for a while before removing it altogether. However, I bet basic is hardly used, so for the sake of expediency and not taxing @AdamRJensen's patience, I am okay with no deprecation period here, although I grumble nonetheless.

I am planning other breaking changes (consistent output of (data,meta)) which cannot have a deprecation period. So since these functions will be affected by a breaking change in the next release, it's better to include this breaking change too; which would minimize the number of times users would potentially need to update their code.

@mikofski It would be great if you review this since you're the original author!

@AdamRJensen AdamRJensen requested a review from mikofski March 22, 2025 19:16
@AdamRJensen
Copy link
Member Author

It would be nice to get this merged soon, so I can move on to the next changes of the PVGIS functions (standardizing the output of data,meta

@mikofski it would be great if you could take a brief look!

Copy link
Member

@mikofski mikofski left a comment

Choose a reason for hiding this comment

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

I think the "nicer" error message @kandersolar requested for get_pvgis_tmy() was accidently added to read_pvgis_hourly() which never accepted 'basic' as an input, so get_pvgis_tmy() still doesn't raise this "nicer" message. This reveals that read_pvgis_hourly() didn't have a test condition (until now) to handle if outputformat was neither 'json' nor 'csv'. Removal of the "basic" test data removed a test if the file extension was neither 'json', 'csv', nor 'epw'

@@ -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'

"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

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

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)

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.

def test_read_pvgis_tmy_basic(expected, meta_expected):
fn = TESTS_DATA_DIR / 'tmy_45.000_8.000_2005_2023.txt'
# XXX: can't infer outputformat from file extensions for basic
with pytest.raises(ValueError, match="pvgis format 'txt' was unknown"):
Copy link
Member

Choose a reason for hiding this comment

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

there are not tests now for raising an exception if either the file extension or pvgis_format was not 'json' or 'csv'. Don't need the basic test file, can create a named temp file instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants