Skip to content

Move repeated WKT POINT formatting in iotools.psm4 into tools helper - #2948

Open
MoxOmega88 wants to merge 2 commits into
pvlib:mainfrom
MoxOmega88:refactor-psm4-wkt
Open

MoxOmega88 wants to merge 2 commits into
pvlib:mainfrom
MoxOmega88:refactor-psm4-wkt

Conversation

@MoxOmega88

@MoxOmega88 MoxOmega88 commented Nov 17, 2026 •

Copy link
Copy Markdown
  • I am familiar with the contributing guidelines
  • I attest that all AI-generated material has been vetted for accuracy and is in compliance with the pvlib license
  • Tests added
  • 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.

Each of the six get_nsrdb_psm4_* functions in pvlib/iotools/psm4.py repeated the same block to format the request location as a well-known text (WKT) POINT, along with the comment # TODO: make format_WKT(object_type, *args) in tools.py (and a "well know text" typo).

This PR resolves that TODO:

  • Adds a private helper pvlib.tools._format_wkt_point(latitude, longitude) with a numpydoc docstring.
  • Replaces the six duplicated blocks in psm4.py with calls to the helper (net -42 lines in psm4.py).
  • Adds parametrized tests in tests/test_tools.py, including a test asserting the helper returns exactly the same string as the previous inline formatting.

There is no change in behaviour: the wkt query parameter sent to the NSRDB API is identical for all six functions. I kept the helper specific to POINT rather than the more general format_WKT(object_type, *args) suggested in the TODO, since POINT is the only geometry pvlib currently uses. Happy to generalize it if preferred.

@github-actions

Copy link
Copy Markdown

Hey @MoxOmega88! 🎉

Thanks for opening your first pull request! We appreciate your
contribution. Please ensure you have reviewed and understood the
contributing guidelines.

If AI is used for any portion of this PR, you must vet the content
for technical accuracy.

Finally, be sure the PR description includes the PR
checklist,
and complete the items you are able to.

@cwhanse

cwhanse commented Nov 17, 2026

Copy link
Copy Markdown
Member

Some useful cleanup here.

I don't think a whatsnew note is needed, since it's improving some internal code with no change to output.

@cwhanse cwhanse added this to the v0.16.2 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants