Skip to content

[FEAT] Refactor location as self-validation dataclass for validating coordinates - #2844

Open
JoLo90 wants to merge 3 commits into
pvlib:mainfrom
JoLo90:refactor_location_as_dataclass
Open

[FEAT] Refactor location as self-validation dataclass for validating coordinates#2844
JoLo90 wants to merge 3 commits into
pvlib:mainfrom
JoLo90:refactor_location_as_dataclass

Conversation

@JoLo90

@JoLo90 JoLo90 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

[WIP]
The PR has two commits; the first commit e8073d0 aims to solve #2843 moving the validation of latitude, longitude and altitude into the dataclass.
While working on the tz attribute, I realized that tz is not very useful (it belongs more to the times parameter than to the site), and its intent is not very clear IMO. So I created a second commit 115aa86, which also removes tz.
The two commits are maybe too much for a single PR (and we should deprecate before deleting), but the intent was to show how lightweight and cleaner Location could be.

@markcampanelli

Copy link
Copy Markdown
Contributor

My analysis of switching to a dataclass suggested that tz would likely be a sore spot. I would be surprised if no other functions/methods made use of this property. Have you verified this @JoLo90? (Sorry if I missed your claims about this somewhere here.)

Comment thread pvlib/location.py
"datetime.tzinfo object (including subclasses)"
@staticmethod
def _validate_value(value: numeric, name: str, lower: numeric, upper: numeric):
if not isinstance(value, numeric):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is where I draw the line with regard to Python fundamentally being dynamically/duck typed and going no further than type hints to suggest the appropriate type (as opposed to checking the type explicitly). I think the range restriction validation is appropriate here, however.

@markcampanelli

Copy link
Copy Markdown
Contributor

Oh I forgot: In @markcampanelli's magical world, this dataclass (and so many others) would be frozen! Oh immutability, thou arst so hard to achieve in shared Python codebases. 😭

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.

[BUG] some get_clearsky models allow calculation with out of range coordinates

2 participants