Skip to content

Commit 01263c2

Browse files
Type Location's tz and pytz attributes as advertised
1 parent 271fd97 commit 01263c2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pvlib/location.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def __init__(self, latitude, longitude, tz='UTC', altitude=None,
7373
self.pytz = pytz.UTC
7474
elif isinstance(tz, datetime.tzinfo):
7575
self.tz = tz.zone
76-
self.pytz = tz
76+
self.pytz = pytz.timezone(tz.zone)
7777
elif isinstance(tz, (int, float)):
78-
self.tz = tz
79-
self.pytz = pytz.FixedOffset(tz*60)
78+
self.tz = f"Etc/GMT{int(-tz):+d}"
79+
self.pytz = pytz.timezone(self.tz)
8080
else:
8181
raise TypeError('Invalid tz specification')
8282

@@ -89,8 +89,10 @@ def __init__(self, latitude, longitude, tz='UTC', altitude=None,
8989

9090
def __repr__(self):
9191
attrs = ['name', 'latitude', 'longitude', 'altitude', 'tz']
92+
# Use None as getattr default in case __repr__ is called during
93+
# initialization before all attributes have been assigned.
9294
return ('Location: \n ' + '\n '.join(
93-
f'{attr}: {getattr(self, attr)}' for attr in attrs))
95+
f'{attr}: {getattr(self, attr, None)}' for attr in attrs))
9496

9597
@classmethod
9698
def from_tmy(cls, tmy_metadata, tmy_data=None, **kwargs):

pvlib/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def localize_to_utc(time, location):
133133
"""
134134
if isinstance(time, dt.datetime):
135135
if time.tzinfo is None:
136-
time = pytz.timezone(location.tz).localize(time)
136+
time = location.pytz.localize(time)
137137
time_utc = time.astimezone(pytz.utc)
138138
else:
139139
try:

0 commit comments

Comments
 (0)