Skip to content

Commit b173dc6

Browse files
author
Sylvain MARIE
committed
Fixed pandas-dev#46319 by using PyUnicode_DecodeLocale to decode the string returned by c_strftime.
1 parent c80bbec commit b173dc6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pandas/_libs/tslibs/period.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ cdef str _period_strftime(int64_t value, int freq, bytes fmt):
13031303
# Execute c_strftime to process the usual datetime directives
13041304
formatted = c_strftime(&dts, <char*>fmt)
13051305

1306-
result = util.char_to_string(formatted)
1306+
result = util.char_to_string_locale(formatted)
13071307
free(formatted)
13081308

13091309
# Now fill the placeholders corresponding to our additional directives

pandas/_libs/tslibs/util.pxd

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ cdef extern from *:
1111
object char_to_string(const char* data)
1212

1313

14+
cdef extern from *:
15+
object PyUnicode_DecodeLocale(const char *str, const char *errors)
16+
17+
18+
cdef inline object char_to_string_locale(const char* data):
19+
"""As opposed to PyUnicode_FromString, use the locale to decode."""
20+
return PyUnicode_DecodeLocale(data, NULL)
21+
22+
1423
cdef extern from "Python.h":
1524
# Note: importing extern-style allows us to declare these as nogil
1625
# functions, whereas `from cpython cimport` does not.

0 commit comments

Comments
 (0)