Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYP: Allow None in Period.strftime #55190

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Period(PeriodMixin):
def _from_ordinal(cls, ordinal: int, freq) -> Period: ...
@classmethod
def now(cls, freq: Frequency = ...) -> Period: ...
def strftime(self, fmt: str) -> str: ...
def strftime(self, fmt: str | None) -> str: ...
def to_timestamp(
self,
freq: str | BaseOffset | None = ...,
Expand Down
5 changes: 3 additions & 2 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2511,11 +2511,12 @@ cdef class _Period(PeriodMixin):
object_state = None, self.freq, self.ordinal
return (Period, object_state)

def strftime(self, fmt: str) -> str:
def strftime(self, fmt: str | None) -> str:
r"""
Returns a formatted string representation of the :class:`Period`.

``fmt`` must be a string containing one or several directives.
``fmt`` must be ``None`` or a string containing one or several directives.
When ``None``, the format will be determined from the frequency of the Period.
The method recognizes the same directives as the :func:`time.strftime`
function of the standard Python distribution, as well as the specific
additional directives ``%f``, ``%F``, ``%q``, ``%l``, ``%u``, ``%n``.
Expand Down