Skip to content

DOC/BUG: Enforce that freq is required in Period.now #49134

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

Merged
merged 1 commit into from
Oct 17, 2022
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
7 changes: 6 additions & 1 deletion pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2288,9 +2288,14 @@ cdef class _Period(PeriodMixin):
return bool(is_leapyear(self.year))

@classmethod
def now(cls, freq=None):
def now(cls, freq):
"""
Return the period of now's date.

Parameters
----------
freq : str, BaseOffset
Frequency to use for the returned period.
"""
return Period(datetime.now(), freq=freq)

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/scalar/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def test_construction(self):
assert i1 == i2
assert i1 == i3

i1 = Period.now("D")
i2 = Period(datetime.now(), freq="D")
i3 = Period.now(offsets.Day())

assert i1 == i2
assert i1 == i3

i1 = Period("1982", freq="min")
i2 = Period("1982", freq="MIN")
assert i1 == i2
Expand Down