Closed
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
start = pd.Period("2020", freq="3D")
a = pd.period_range(start, periods=2, freq=start.freq)
assert a[1] == start + 1
# Fails
b = pd.period_range(start, periods=2)
assert b[1] == start + 1
Issue Description
The issue lies in _get_ordinal_range
:
pandas/pandas/core/arrays/period.py
Lines 1044 to 1089 in 37d4c31
A fix could be to replace:
pandas/pandas/core/arrays/period.py
Lines 1068 to 1072 in 37d4c31
with
if freq is None:
if is_start_per:
freq = start.freq
mult = freq.n
elif is_end_per:
freq = end.freq
mult = freq.n
Expected Behavior
Omitting the freq
argument of pd.period_range
should be the same as passing the freq
of the start or end field to it via freq=
.
Installed Versions
Not relevant to issue.