Skip to content

Commit 0d18ab1

Browse files
mroeschkeNo-Stream
authored andcommitted
BUG: Return local Timestamp.weekday_name attribute (pandas-dev#17354) (pandas-dev#17377)
1 parent 6ffb748 commit 0d18ab1

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ Conversion
399399
- Fixed the return type of ``IntervalIndex.is_non_overlapping_monotonic`` to be a Python ``bool`` for consistency with similar attributes/methods. Previously returned a ``numpy.bool_``. (:issue:`17237`)
400400
- Bug in ``IntervalIndex.is_non_overlapping_monotonic`` when intervals are closed on both sides and overlap at a point (:issue:`16560`)
401401
- Bug in :func:`Series.fillna` returns frame when ``inplace=True`` and ``value`` is dict (:issue:`16156`)
402+
- Bug in :attr:`Timestamp.weekday_name` returning a UTC-based weekday name when localized to a timezone (:issue:`17354`)
402403

403404
Indexing
404405
^^^^^^^^

pandas/_libs/tslib.pyx

+18-4
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,7 @@ class Timestamp(_Timestamp):
532532

533533
@property
534534
def weekday_name(self):
535-
out = get_date_name_field(
536-
np.array([self.value], dtype=np.int64), 'weekday_name')
537-
return out[0]
535+
return self._get_named_field('weekday_name')
538536

539537
@property
540538
def dayofyear(self):
@@ -1269,13 +1267,29 @@ cdef class _Timestamp(datetime):
12691267
# same timezone if specified)
12701268
return datetime.__sub__(self, other)
12711269

1272-
cpdef _get_field(self, field):
1270+
cdef int64_t _maybe_convert_value_to_local(self):
1271+
"""Convert UTC i8 value to local i8 value if tz exists"""
1272+
cdef:
1273+
int64_t val
12731274
val = self.value
12741275
if self.tz is not None and not _is_utc(self.tz):
12751276
val = tz_convert_single(self.value, 'UTC', self.tz)
1277+
return val
1278+
1279+
cpdef _get_field(self, field):
1280+
cdef:
1281+
int64_t val
1282+
val = self._maybe_convert_value_to_local()
12761283
out = get_date_field(np.array([val], dtype=np.int64), field)
12771284
return int(out[0])
12781285

1286+
cpdef _get_named_field(self, field):
1287+
cdef:
1288+
int64_t val
1289+
val = self._maybe_convert_value_to_local()
1290+
out = get_date_name_field(np.array([val], dtype=np.int64), field)
1291+
return out[0]
1292+
12791293
cpdef _get_start_end_field(self, field):
12801294
month_kw = self.freq.kwds.get(
12811295
'startingMonth', self.freq.kwds.get(

pandas/tests/scalar/test_timestamp.py

+8
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ def check(value, equal):
555555
for end in ends:
556556
assert getattr(ts, end)
557557

558+
@pytest.mark.parametrize('data, expected',
559+
[(Timestamp('2017-08-28 23:00:00'), 'Monday'),
560+
(Timestamp('2017-08-28 23:00:00', tz='EST'),
561+
'Monday')])
562+
def test_weekday_name(self, data, expected):
563+
# GH 17354
564+
assert data.weekday_name == expected
565+
558566
def test_pprint(self):
559567
# GH12622
560568
import pprint

0 commit comments

Comments
 (0)