Skip to content

ENH: Creating a now Period for a frequency of a multiple unit #53936

Open
@eumiro

Description

@eumiro

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wish there was a straightforward way to create the now Period for the frequency that is a multiple of a unit (e.g. "15T")

Feature Description

>>> pd.Period.now("15T")
Period('2023-06-29 12:34', '15T')

>>> pd.Period.now("15T", floor=True)
Period('2023-06-29 12:30', '15T')

The first case is the status quo: the Period starts in the current minute. The second is my idea (and someone will certainly have a better name replacement for the floor= parameter) and it starts at the previous 15T stop (:00, :15, :30, :45).

Alternative Solutions

The most compact way I found to get the right result is:

>>> pd.Timestamp.now().floor("15T").to_period("15T")
Period('2023-06-29 12:30', '15T')

with 15T appearing twice in the line, which is what I'd like to avoid.

My proposal should work also for frequencies that do not fit within one hour:

>>> pd.Period.now("17T", floor=True)
>>> pd.Timestamp.now().floor("17T").to_period("17T")
Period('2023-06-29 12:31', '17T')

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds DiscussionRequires discussion from core team before further actionPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions