@@ -22,6 +22,10 @@ from np_datetime cimport (pandas_datetimestruct, pandas_timedeltastruct,
2222 days_per_month_table, is_leapyear, dayofweek)
2323from nattype cimport NPY_NAT
2424
25+ from pandas._libs.tslibs.strptime import LocaleTime
26+
27+ import locale
28+ from pandas.util.testing import set_locale
2529
2630def build_field_sarray (ndarray[int64_t] dtindex ):
2731 """
@@ -67,7 +71,8 @@ def build_field_sarray(ndarray[int64_t] dtindex):
6771
6872@ cython.wraparound (False )
6973@ cython.boundscheck (False )
70- def get_date_name_field (ndarray[int64_t] dtindex , object field ):
74+ def get_date_name_field (ndarray[int64_t] dtindex , object field ,
75+ object time_locale = None ):
7176 """
7277 Given a int64-based datetime index, return array of strings of date
7378 name based on requested field (e.g. weekday_name)
@@ -77,16 +82,15 @@ def get_date_name_field(ndarray[int64_t] dtindex, object field):
7782 ndarray[object ] out
7883 pandas_datetimestruct dts
7984 int dow
80-
81- _dayname = np.array(
82- [' Monday' , ' Tuesday' , ' Wednesday' , ' Thursday' ,
83- ' Friday' , ' Saturday' , ' Sunday' ],
84- dtype = np.object_)
85+ object locale_time = LocaleTime()
8586
8687 count = len (dtindex)
8788 out = np.empty(count, dtype = object )
8889
8990 if field == ' weekday_name' :
91+ _dayname = np.array([' Monday' , ' Tuesday' , ' Wednesday' , ' Thursday' ,
92+ ' Friday' , ' Saturday' , ' Sunday' ],
93+ dtype = np.object_)
9094 for i in range (count):
9195 if dtindex[i] == NPY_NAT:
9296 out[i] = np.nan
@@ -95,6 +99,40 @@ def get_date_name_field(ndarray[int64_t] dtindex, object field):
9599 dt64_to_dtstruct(dtindex[i], & dts)
96100 dow = dayofweek(dts.year, dts.month, dts.day)
97101 out[i] = _dayname[dow]
102+ if field == ' day_name' :
103+ if time_locale is None :
104+ _dayname = np.array([' monday' , ' tuesday' , ' wednesday' , ' thursday' ,
105+ ' friday' , ' saturday' , ' sunday' ],
106+ dtype = np.object_)
107+ else :
108+ with set_locale(time_locale, locale.LC_TIME):
109+ locale_time = LocaleTime()
110+ _dayname = np.array(locale_time.f_weekday, dtype = np.object_)
111+ for i in range (count):
112+ if dtindex[i] == NPY_NAT:
113+ out[i] = np.nan
114+ continue
115+
116+ dt64_to_dtstruct(dtindex[i], & dts)
117+ dow = dayofweek(dts.year, dts.month, dts.day)
118+ out[i] = _dayname[dow].capitalize()
119+ return out
120+ elif field == ' month_name' :
121+ if time_locale is None :
122+ _monthname = np.array([' ' , ' monday' , ' tuesday' , ' wednesday' ,
123+ ' thursday' , ' friday' , ' saturday' , ' sunday' ],
124+ dtype = np.object_)
125+ else :
126+ with set_locale(time_locale, locale.LC_TIME):
127+ locale_time = LocaleTime()
128+ _monthname = np.array(locale_time.f_month, dtype = np.object_)
129+ for i in range (count):
130+ if dtindex[i] == NPY_NAT:
131+ out[i] = np.nan
132+ continue
133+
134+ dt64_to_dtstruct(dtindex[i], & dts)
135+ out[i] = _monthname[dts.month].capitalize()
98136 return out
99137
100138 raise ValueError (" Field %s not supported" % field)
0 commit comments