Skip to content

Commit 942beba

Browse files
authored
CLN: disallow passing tuples for Period freq (#34658)
* CLN: disallow passing tuples for Period freq * whatsnew
1 parent f093f07 commit 942beba

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ Backwards incompatible API changes
403403
- :func:`read_excel` no longer takes ``**kwds`` arguments. This means that passing in keyword ``chunksize`` now raises a ``TypeError``
404404
(previously raised a ``NotImplementedError``), while passing in keyword ``encoding`` now raises a ``TypeError`` (:issue:`34464`)
405405
- :func: `merge` now checks ``suffixes`` parameter type to be ``tuple`` and raises ``TypeError``, whereas before a ``list`` or ``set`` were accepted and that the ``set`` could produce unexpected results (:issue:`33740`)
406+
- :class:`Period` no longer accepts tuples for the ``freq`` argument (:issue:`34658`)
406407

407408
``MultiIndex.get_indexer`` interprets `method` argument differently
408409
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

pandas/_libs/tslibs/period.pyx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1507,9 +1507,10 @@ cdef class _Period:
15071507
-------
15081508
DateOffset
15091509
"""
1510-
if isinstance(freq, (int, tuple)):
1511-
code, stride = get_freq_code(freq)
1512-
freq = get_freq_str(code, stride)
1510+
if isinstance(freq, int):
1511+
# We already have a dtype code
1512+
dtype = PeriodDtypeBase(freq)
1513+
freq = dtype.date_offset
15131514

15141515
freq = to_offset(freq)
15151516

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def _parsed_string_to_bounds(self, reso: str, parsed: datetime):
501501
raise KeyError
502502

503503
grp = get_freq_group(reso)
504-
per = Period(parsed, freq=(grp, 1))
504+
per = Period(parsed, freq=grp)
505505
start, end = per.start_time, per.end_time
506506

507507
# GH 24076

pandas/core/indexes/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def _parsed_string_to_bounds(self, reso: str, parsed: datetime):
574574
raise KeyError(reso)
575575

576576
grp = get_freq_group(reso)
577-
iv = Period(parsed, freq=(grp, 1))
577+
iv = Period(parsed, freq=grp)
578578
return (iv.asfreq(self.freq, how="start"), iv.asfreq(self.freq, how="end"))
579579

580580
def _validate_partial_date_slice(self, reso: str):

0 commit comments

Comments
 (0)