Skip to content

Commit a1cd27b

Browse files
committed
address review missed files
1 parent 6f4a962 commit a1cd27b

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

pandas/_libs/tslibs/timestamps.pyx

+21-18
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ from util cimport (is_datetime64_object, is_timedelta64_object,
2121
INT64_MAX)
2222

2323
cimport ccalendar
24-
from ccalendar import get_locale_names, MONTHS_FULL, DAYS_FULL
2524
from conversion import tz_localize_to_utc, date_normalize
2625
from conversion cimport (tz_convert_single, _TSObject,
2726
convert_to_tsobject, convert_datetime_to_tsobject)
28-
from fields import get_date_field, get_start_end_field
27+
from fields import get_start_end_field, get_date_name_field
2928
from nattype import NaT
3029
from nattype cimport NPY_NAT
3130
from np_datetime import OutOfBoundsDatetime
@@ -352,6 +351,16 @@ cdef class _Timestamp(datetime):
352351
field, freqstr, month_kw)
353352
return out[0]
354353

354+
cpdef _get_date_name_field(self, object field, object locale):
355+
cdef:
356+
int64_t val
357+
ndarray out
358+
359+
val = self._maybe_convert_value_to_local()
360+
out = get_date_name_field(np.array([val], dtype=np.int64),
361+
field, locale=locale)
362+
return out[0]
363+
355364
@property
356365
def _repr_base(self):
357366
return '{date} {time}'.format(date=self._date_repr,
@@ -702,45 +711,39 @@ class Timestamp(_Timestamp):
702711
def dayofweek(self):
703712
return self.weekday()
704713

705-
def day_name(self, time_locale=None):
714+
def day_name(self, locale=None):
706715
"""
707716
Return the day name of the Timestamp with specified locale.
708717
709718
Parameters
710719
----------
711-
time_locale : string, default None (English locale)
720+
locale : string, default None (English locale)
712721
locale determining the language in which to return the day name
713722
714723
Returns
715724
-------
716725
day_name : string
726+
727+
.. versionadded:: 0.23.0
717728
"""
718-
if time_locale is None:
719-
names = DAYS_FULL
720-
else:
721-
names = get_locale_names('f_weekday', time_locale)
722-
days = dict(enumerate(names))
723-
return days[self.weekday()].capitalize()
729+
return self._get_date_name_field('day_name', locale)
724730

725-
def month_name(self, time_locale=None):
731+
def month_name(self, locale=None):
726732
"""
727733
Return the month name of the Timestamp with specified locale.
728734
729735
Parameters
730736
----------
731-
time_locale : string, default None (English locale)
737+
locale : string, default None (English locale)
732738
locale determining the language in which to return the month name
733739
734740
Returns
735741
-------
736742
month_name : string
743+
744+
.. versionadded:: 0.23.0
737745
"""
738-
if time_locale is None:
739-
names = MONTHS_FULL
740-
else:
741-
names = get_locale_names('f_month', time_locale)
742-
months = dict(enumerate(names))
743-
return months[self.month].capitalize()
746+
return self._get_date_name_field('month_name', locale)
744747

745748
@property
746749
def weekday_name(self):

pandas/tests/indexes/datetimes/test_misc.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ def test_datetimeindex_accessors(self):
245245
@pytest.mark.skipif(not tm.get_locales(), reason='No available locales')
246246
@pytest.mark.parametrize('time_locale', tm.get_locales() + [None])
247247
def test_datetime_name_accessors(self, time_locale):
248+
# Test Monday -> Sunday and January -> December, in that sequence
248249
if time_locale is None:
250+
# If the time_locale is None, day-name and month_name should
251+
# return the english attributes
249252
expected_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
250253
'Friday', 'Saturday', 'Sunday']
251254
expected_months = ['January', 'February', 'March', 'April', 'May',
@@ -264,23 +267,27 @@ def test_datetime_name_accessors(self, time_locale):
264267
for day, name, eng_name in zip(range(4, 11),
265268
expected_days,
266269
english_days):
267-
# Test Monday -> Sunday
268270
name = name.capitalize()
269271
assert dti.weekday_name[day] == eng_name
270-
assert dti.day_name(time_locale=time_locale)[day] == name
272+
assert dti.day_name(locale=time_locale)[day] == name
271273
ts = Timestamp(datetime(2016, 4, day))
272274
assert ts.weekday_name == eng_name
273-
assert ts.day_name(time_locale=time_locale) == name
275+
assert ts.day_name(locale=time_locale) == name
276+
dti = dti.append(DatetimeIndex([pd.NaT]))
277+
assert np.isnan(dti.day_name(locale=time_locale)[-1])
278+
ts = Timestamp(pd.NaT)
279+
assert np.isnan(ts.day_name(locale=time_locale))
274280

275281
# GH 12805
276282
dti = DatetimeIndex(freq='M', start='2012', end='2013')
277-
# Test January -> December
278-
result = dti.month_name(time_locale=time_locale)
283+
result = dti.month_name(locale=time_locale)
279284
expected = Index([month.capitalize() for month in expected_months])
280285
tm.assert_index_equal(result, expected)
281286
for date, expected in zip(dti, expected_months):
282-
result = date.month_name(time_locale=time_locale)
287+
result = date.month_name(locale=time_locale)
283288
assert result == expected.capitalize()
289+
dti = dti.append(DatetimeIndex([pd.NaT]))
290+
assert np.isnan(dti.month_name(locale=time_locale)[-1])
284291

285292
def test_nanosecond_field(self):
286293
dti = DatetimeIndex(np.arange(10))

0 commit comments

Comments
 (0)