@@ -20,6 +20,10 @@ from np_datetime cimport (pandas_datetimestruct, pandas_timedeltastruct,
20
20
dt64_to_dtstruct, td64_to_tdstruct)
21
21
from nattype cimport NPY_NAT
22
22
23
+ from pandas._libs.tslibs.strptime import LocaleTime
24
+
25
+ import locale
26
+ from pandas.util.testing import set_locale
23
27
24
28
def get_time_micros (ndarray[int64_t] dtindex ):
25
29
"""
@@ -85,7 +89,8 @@ def build_field_sarray(ndarray[int64_t] dtindex):
85
89
86
90
@ cython.wraparound (False )
87
91
@ cython.boundscheck (False )
88
- def get_date_name_field (ndarray[int64_t] dtindex , object field ):
92
+ def get_date_name_field (ndarray[int64_t] dtindex , object field ,
93
+ object time_locale = None ):
89
94
"""
90
95
Given a int64-based datetime index, return array of strings of date
91
96
name based on requested field (e.g. weekday_name)
@@ -95,16 +100,15 @@ def get_date_name_field(ndarray[int64_t] dtindex, object field):
95
100
ndarray[object ] out
96
101
pandas_datetimestruct dts
97
102
int dow
98
-
99
- _dayname = np.array(
100
- [' Monday' , ' Tuesday' , ' Wednesday' , ' Thursday' ,
101
- ' Friday' , ' Saturday' , ' Sunday' ],
102
- dtype = np.object_)
103
+ object locale_time = LocaleTime()
103
104
104
105
count = len (dtindex)
105
106
out = np.empty(count, dtype = object )
106
107
107
108
if field == ' weekday_name' :
109
+ _dayname = np.array([' Monday' , ' Tuesday' , ' Wednesday' , ' Thursday' ,
110
+ ' Friday' , ' Saturday' , ' Sunday' ],
111
+ dtype = np.object_)
108
112
for i in range (count):
109
113
if dtindex[i] == NPY_NAT:
110
114
out[i] = np.nan
@@ -113,6 +117,40 @@ def get_date_name_field(ndarray[int64_t] dtindex, object field):
113
117
dt64_to_dtstruct(dtindex[i], & dts)
114
118
dow = dayofweek(dts.year, dts.month, dts.day)
115
119
out[i] = _dayname[dow]
120
+ if field == ' day_name' :
121
+ if time_locale is None :
122
+ _dayname = np.array([' monday' , ' tuesday' , ' wednesday' , ' thursday' ,
123
+ ' friday' , ' saturday' , ' sunday' ],
124
+ dtype = np.object_)
125
+ else :
126
+ with set_locale(time_locale, locale.LC_TIME):
127
+ locale_time = LocaleTime()
128
+ _dayname = np.array(locale_time.f_weekday, 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
+ dow = dayofweek(dts.year, dts.month, dts.day)
136
+ out[i] = _dayname[dow].capitalize()
137
+ return out
138
+ elif field == ' month_name' :
139
+ if time_locale is None :
140
+ _monthname = np.array([' ' , ' monday' , ' tuesday' , ' wednesday' ,
141
+ ' thursday' , ' friday' , ' saturday' , ' sunday' ],
142
+ dtype = np.object_)
143
+ else :
144
+ with set_locale(time_locale, locale.LC_TIME):
145
+ locale_time = LocaleTime()
146
+ _monthname = np.array(locale_time.f_month, dtype = np.object_)
147
+ for i in range (count):
148
+ if dtindex[i] == NPY_NAT:
149
+ out[i] = np.nan
150
+ continue
151
+
152
+ dt64_to_dtstruct(dtindex[i], & dts)
153
+ out[i] = _monthname[dts.month].capitalize()
116
154
return out
117
155
118
156
raise ValueError (" Field %s not supported" % field)
0 commit comments