Skip to content

Commit 30814ee

Browse files
BUG: period_range gives incorrect output (#53709)
* bug fix * Added testcases
1 parent ac3153b commit 30814ee

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ Other
567567
- Bug in :meth:`Series.align`, :meth:`DataFrame.align`, :meth:`Series.reindex`, :meth:`DataFrame.reindex`, :meth:`Series.interpolate`, :meth:`DataFrame.interpolate`, incorrectly failing to raise with method="asfreq" (:issue:`53620`)
568568
- Bug in :meth:`Series.map` when giving a callable to an empty series, the returned series had ``object`` dtype. It now keeps the original dtype (:issue:`52384`)
569569
- Bug in :meth:`Series.memory_usage` when ``deep=True`` throw an error with Series of objects and the returned value is incorrect, as it does not take into account GC corrections (:issue:`51858`)
570+
- Bug in :meth:`period_range` the default behavior when freq was not passed as an argument was incorrect(:issue:`53687`)
570571
- Fixed incorrect ``__name__`` attribute of ``pandas._libs.json`` (:issue:`52898`)
571572

572573
.. ***DO NOT USE THIS SECTION***

pandas/core/arrays/period.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,7 @@ def _get_ordinal_range(start, end, periods, freq, mult: int = 1):
11831183
freq = end.freq
11841184
else: # pragma: no cover
11851185
raise ValueError("Could not infer freq from start/end")
1186+
mult = freq.n
11861187

11871188
if periods is not None:
11881189
periods = periods * mult

pandas/tests/indexes/period/test_constructors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ def test_constructor_corner(self):
137137
exp = period_range("2007-01", periods=10, freq="M")
138138
tm.assert_index_equal(result, exp)
139139

140+
def test_constructor_with_without_freq(self):
141+
# GH53687
142+
start = Period("2002-01-01 00:00", freq="30T")
143+
exp = period_range(start=start, periods=5, freq=start.freq)
144+
result = period_range(start=start, periods=5)
145+
tm.assert_index_equal(exp, result)
146+
140147
def test_constructor_fromarraylike(self):
141148
idx = period_range("2007-01", periods=20, freq="M")
142149

0 commit comments

Comments
 (0)