Skip to content

Commit 45cf653

Browse files
rhshadrachhedeershowk
authored andcommitted
TYP: Allow None in Period.strftime (pandas-dev#55190)
* TYP: Allow None in strftime * Change pyi * Add description to docstring
1 parent 259ee6c commit 45cf653

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

pandas/_libs/tslibs/period.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Period(PeriodMixin):
9090
def _from_ordinal(cls, ordinal: int, freq) -> Period: ...
9191
@classmethod
9292
def now(cls, freq: Frequency = ...) -> Period: ...
93-
def strftime(self, fmt: str) -> str: ...
93+
def strftime(self, fmt: str | None) -> str: ...
9494
def to_timestamp(
9595
self,
9696
freq: str | BaseOffset | None = ...,

pandas/_libs/tslibs/period.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2511,11 +2511,12 @@ cdef class _Period(PeriodMixin):
25112511
object_state = None, self.freq, self.ordinal
25122512
return (Period, object_state)
25132513

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

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

0 commit comments

Comments
 (0)