Skip to content

Commit ab57006

Browse files
committed
Rebase and add depreciation message
1 parent e10b1c9 commit ab57006

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

doc/source/whatsnew/v0.23.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ Other Enhancements
202202
- ``Resampler`` objects now have a functioning :attr:`~pandas.core.resample.Resampler.pipe` method.
203203
Previously, calls to ``pipe`` were diverted to the ``mean`` method (:issue:`17905`).
204204
- :func:`~pandas.api.types.is_scalar` now returns ``True`` for ``DateOffset`` objects (:issue:`18943`).
205+
- :meth:`Timestamp.month_name`, :meth:`DatetimeIndex.month_name`, and :meth:`Series.dt.month_name` are now available (:issue:`12805`)
206+
- :meth:`Timestamp.day_name` and :meth:`DatetimeIndex.day_name` are now available to return day names with a specified locale (:issue:`12806`)
205207

206208
.. _whatsnew_0230.api_breaking:
207209

pandas/_libs/tslibs/timestamps.pyx

+55
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# -*- coding: utf-8 -*-
22
# cython: profile=False
33
import warnings
4+
import locale
5+
6+
from pandas.util.testing import set_locale
47

58
from cpython cimport (PyObject_RichCompareBool, PyObject_RichCompare,
69
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE)
@@ -34,6 +37,7 @@ from np_datetime cimport (reverse_ops, cmp_scalar, check_dts_bounds,
3437
from timedeltas import Timedelta
3538
from timedeltas cimport delta_to_nanoseconds
3639
from timezones cimport get_timezone, is_utc, maybe_get_tz, treat_tz_as_pytz
40+
from strptime import LocaleTime
3741

3842
# ----------------------------------------------------------------------
3943
# Constants
@@ -685,8 +689,59 @@ class Timestamp(_Timestamp):
685689
def dayofweek(self):
686690
return self.weekday()
687691

692+
def day_name(self, time_locale=None):
693+
"""
694+
Return the day name of the Timestamp with specified locale.
695+
696+
Parameters
697+
----------
698+
time_locale : string, default None (English locale)
699+
locale determining the language in which to return the day name
700+
701+
Returns
702+
-------
703+
day_name : string
704+
"""
705+
if time_locale is None:
706+
days = {0: 'monday', 1: 'tuesday', 2: 'wednesday',
707+
3: 'thursday', 4: 'friday', 5: 'saturday',
708+
6: 'sunday'}
709+
else:
710+
with set_locale(time_locale, locale.LC_TIME):
711+
locale_time = LocaleTime()
712+
days = dict(enumerate(locale_time.f_weekday))
713+
return days[self.weekday()].capitalize()
714+
715+
def month_name(self, time_locale=None):
716+
"""
717+
Return the month name of the Timestamp with specified locale.
718+
719+
Parameters
720+
----------
721+
time_locale : string, default None (English locale)
722+
locale determining the language in which to return the month name
723+
724+
Returns
725+
-------
726+
month_name : string
727+
"""
728+
if time_locale is None:
729+
months = {1: 'january', 2: 'february', 3: 'march',
730+
4: 'april', 5: 'may', 6: 'june', 7: 'july',
731+
8: 'august', 9: 'september', 10: 'october',
732+
11: 'november', 12: 'december'}
733+
else:
734+
with set_locale(time_locale, locale.LC_TIME):
735+
locale_time = LocaleTime()
736+
months = dict(enumerate(locale_time.f_month))
737+
return months[self.month].capitalize()
738+
688739
@property
689740
def weekday_name(self):
741+
"""
742+
.. depreciated:: 0.23.0
743+
Use ``Timestamp.day_name()`` instead
744+
"""
690745
cdef dict wdays = {0: 'Monday', 1: 'Tuesday', 2: 'Wednesday',
691746
3: 'Thursday', 4: 'Friday', 5: 'Saturday',
692747
6: 'Sunday'}

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ def freq(self, value):
16881688
weekday_name = _field_accessor(
16891689
'weekday_name',
16901690
'weekday_name',
1691-
"The name of day in a week (ex: Friday)\n\n.. versionadded:: 0.18.1")
1691+
"The name of day in a week (ex: Friday)\n\n.. depreciated:: 0.23.0")
16921692

16931693
dayofyear = _field_accessor('dayofyear', 'doy',
16941694
"The ordinal day of the year")

0 commit comments

Comments
 (0)