Skip to content

BUG: UnicodeError when using Period.strftime with non-utf8 locale #46319

Closed
@smarie

Description

@smarie

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import locale

locale.setlocale(locale.LC_ALL, "zh_CN")
p = pd.Period("2018-03-11 13:00", freq="H")
print(p.strftime("%p"))  # UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf ...

Issue Description

Period.strftime("%p") prints the locale-specific version of AM or PM. When the locale uses a non-utf8 compliant encoding, it crashes.

This bug does not happen with others, for example Timestamp.strftime.

Expected Behavior

No error, printing the actual string representing AM or PM

Installed Versions

This is on the main branch head

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugOutput-Formatting__repr__ of pandas objects, to_stringPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions