@@ -76,9 +76,7 @@ def tz_to_dtype(tz):
76
76
77
77
def _field_accessor (name , field , docstring = None ):
78
78
def f (self ):
79
- values = self .asi8
80
- if self .tz is not None and not timezones .is_utc (self .tz ):
81
- values = self ._local_timestamps ()
79
+ values = self ._local_timestamps ()
82
80
83
81
if field in self ._bool_ops :
84
82
if field .endswith (("start" , "end" )):
@@ -731,6 +729,8 @@ def _local_timestamps(self):
731
729
This is used to calculate time-of-day information as if the timestamps
732
730
were timezone-naive.
733
731
"""
732
+ if self .tz is None or timezones .is_utc (self .tz ):
733
+ return self .asi8
734
734
return tzconversion .tz_convert_from_utc (self .asi8 , self .tz )
735
735
736
736
def tz_convert (self , tz ):
@@ -1167,10 +1167,7 @@ def month_name(self, locale=None):
1167
1167
>>> idx.month_name()
1168
1168
Index(['January', 'February', 'March'], dtype='object')
1169
1169
"""
1170
- if self .tz is not None and not timezones .is_utc (self .tz ):
1171
- values = self ._local_timestamps ()
1172
- else :
1173
- values = self .asi8
1170
+ values = self ._local_timestamps ()
1174
1171
1175
1172
result = fields .get_date_name_field (values , "month_name" , locale = locale )
1176
1173
result = self ._maybe_mask_results (result , fill_value = None )
@@ -1200,10 +1197,7 @@ def day_name(self, locale=None):
1200
1197
>>> idx.day_name()
1201
1198
Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object')
1202
1199
"""
1203
- if self .tz is not None and not timezones .is_utc (self .tz ):
1204
- values = self ._local_timestamps ()
1205
- else :
1206
- values = self .asi8
1200
+ values = self ._local_timestamps ()
1207
1201
1208
1202
result = fields .get_date_name_field (values , "day_name" , locale = locale )
1209
1203
result = self ._maybe_mask_results (result , fill_value = None )
@@ -1217,10 +1211,7 @@ def time(self):
1217
1211
# If the Timestamps have a timezone that is not UTC,
1218
1212
# convert them into their i8 representation while
1219
1213
# keeping their timezone and not using UTC
1220
- if self .tz is not None and not timezones .is_utc (self .tz ):
1221
- timestamps = self ._local_timestamps ()
1222
- else :
1223
- timestamps = self .asi8
1214
+ timestamps = self ._local_timestamps ()
1224
1215
1225
1216
return ints_to_pydatetime (timestamps , box = "time" )
1226
1217
@@ -1241,10 +1232,7 @@ def date(self):
1241
1232
# If the Timestamps have a timezone that is not UTC,
1242
1233
# convert them into their i8 representation while
1243
1234
# keeping their timezone and not using UTC
1244
- if self .tz is not None and not timezones .is_utc (self .tz ):
1245
- timestamps = self ._local_timestamps ()
1246
- else :
1247
- timestamps = self .asi8
1235
+ timestamps = self ._local_timestamps ()
1248
1236
1249
1237
return ints_to_pydatetime (timestamps , box = "date" )
1250
1238
@@ -1283,10 +1271,7 @@ def isocalendar(self):
1283
1271
"""
1284
1272
from pandas import DataFrame
1285
1273
1286
- if self .tz is not None and not timezones .is_utc (self .tz ):
1287
- values = self ._local_timestamps ()
1288
- else :
1289
- values = self .asi8
1274
+ values = self ._local_timestamps ()
1290
1275
sarray = fields .build_isocalendar_sarray (values )
1291
1276
iso_calendar_df = DataFrame (
1292
1277
sarray , columns = ["year" , "week" , "day" ], dtype = "UInt32"
0 commit comments