Description
Feature Type
-
Adding new functionality to pandas
-
Changing existing functionality in pandas
-
Removing existing functionality in pandas
Problem Description
Currently, pandas.Period()
does not support multi-year spans defined in a single string input. This is a limitation in use cases that require defining and working with multi-year periods for financial reports, fiscal years, and research studies.
Proposed Feature: Extend pandas.Period()
and/or pandas.period_range()
to support multi-year spans using a standardized format. Possible formats:
- "2019-2021" → Represents a multi-year period (Jan 1, 2019 - Dec 31, 2021)
- "2020Q2-2023Q1" → Represents a quarter-based multi-year period
Why Is This Needed?
pandas.Period("2019", freq="Y")
exists, butpandas.Period("2019-2021", freq="Y")
throws an error.- Business reports and research commonly span multiple years.
- This would add consistency to how pandas handles date-based period parsing.
Feature Description
- Modify
pandas/_libs/tslibs/parsing.pyx
to recognize "YYYY-YYYY" format. - Adjust
pandas.Period()
parsing logic to correctly interpret multi-year ranges. - Implement unit tests for expected behavior.
Alternative Solutions
-
Manual Conversion – Users manually parse ordinal dates (YYYY-DDD) or multi-year spans (YYYY-YYYY) and convert them using
pd.Timestamp
orpd.period_range()
.
Limitation: Requires extra effort and lacks built-in support. -
Using
dateutil
–dateutil.parser.isoparse()
supports ordinal dates but does not return Period. Multi-year spans require additional handling.
Limitation: Not integrated with pandas.Period. -
Extending
pd.to_datetime()
– Modify pandas timestamp parsing instead of Period.
Limitation:to_datetime()
is focused on timestamp conversion rather than handling periods, making it a less natural fit.
Additional Context
No response