From 49b02fc2e12b06295cf814439b776203150f3f4f Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Mon, 18 Sep 2023 17:39:11 -0400 Subject: [PATCH 1/3] TYP: Allow None in strftime --- pandas/_libs/tslibs/period.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index c37e9cd7ef1f3..81be76ee4147e 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -2511,7 +2511,7 @@ 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`. From 3cd1ecb8a9121389b9a266aebf7566d7ec4e9eca Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Mon, 18 Sep 2023 17:41:10 -0400 Subject: [PATCH 2/3] Change pyi --- pandas/_libs/tslibs/period.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/period.pyi b/pandas/_libs/tslibs/period.pyi index c85865fea8fd0..a4aecd2ce0a09 100644 --- a/pandas/_libs/tslibs/period.pyi +++ b/pandas/_libs/tslibs/period.pyi @@ -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 = ..., From 39190990fe1ca25f1ee0db922e26bf459099f102 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Tue, 19 Sep 2023 06:52:30 -0400 Subject: [PATCH 3/3] Add description to docstring --- pandas/_libs/tslibs/period.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 81be76ee4147e..21937ab2519e4 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -2515,7 +2515,8 @@ cdef class _Period(PeriodMixin): 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``.