Skip to content

Commit 991af8f

Browse files
mroeschkejbrockmendel
authored andcommitted
BUG: Return local Timestamp.weekday_name attribute (pandas-dev#17354) (pandas-dev#17377)
1 parent b507379 commit 991af8f

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
@@ -534,9 +534,7 @@ class Timestamp(_Timestamp):
534534

535535
@property
536536
def weekday_name(self):
537-
out = get_date_name_field(
538-
np.array([self.value], dtype=np.int64), 'weekday_name')
539-
return out[0]
537+
return self._get_named_field('weekday_name')
540538

541539
@property
542540
def dayofyear(self):
@@ -1271,13 +1269,29 @@ cdef class _Timestamp(datetime):
12711269
# same timezone if specified)
12721270
return datetime.__sub__(self, other)
12731271

1274-
cpdef _get_field(self, field):
1272+
cdef int64_t _maybe_convert_value_to_local(self):
1273+
"""Convert UTC i8 value to local i8 value if tz exists"""
1274+
cdef:
1275+
int64_t val
12751276
val = self.value
12761277
if self.tz is not None and not _is_utc(self.tz):
12771278
val = tz_convert_single(self.value, 'UTC', self.tz)
1279+
return val
1280+
1281+
cpdef _get_field(self, field):
1282+
cdef:
1283+
int64_t val
1284+
val = self._maybe_convert_value_to_local()
12781285
out = get_date_field(np.array([val], dtype=np.int64), field)
12791286
return int(out[0])
12801287

1288+
cpdef _get_named_field(self, field):
1289+
cdef:
1290+
int64_t val
1291+
val = self._maybe_convert_value_to_local()
1292+
out = get_date_name_field(np.array([val], dtype=np.int64), field)
1293+
return out[0]
1294+
12811295
cpdef _get_start_end_field(self, field):
12821296
month_kw = self.freq.kwds.get(
12831297
'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)