From 5e316ec3cbb689c9cfeaa3bcc50f26dafcb4cd26 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 8 Jun 2020 15:32:30 -0700 Subject: [PATCH 1/2] CLN: disallow passing tuples for Period freq --- pandas/_libs/tslibs/period.pyx | 7 ++++--- pandas/core/indexes/datetimes.py | 2 +- pandas/core/indexes/period.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 55148041c1718..e080cf4a44912 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1536,9 +1536,10 @@ cdef class _Period: ------- DateOffset """ - if isinstance(freq, (int, tuple)): - code, stride = get_freq_code(freq) - freq = get_freq_str(code, stride) + if isinstance(freq, int): + # We already have a dtype code + dtype = PeriodDtypeBase(freq) + freq = dtype.date_offset freq = to_offset(freq) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e1f0221eaee65..d8654dee56319 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -501,7 +501,7 @@ def _parsed_string_to_bounds(self, reso: str, parsed: datetime): raise KeyError grp = get_freq_group(reso) - per = Period(parsed, freq=(grp, 1)) + per = Period(parsed, freq=grp) start, end = per.start_time, per.end_time # GH 24076 diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 14922000c9707..0fafeef078d78 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -574,7 +574,7 @@ def _parsed_string_to_bounds(self, reso: str, parsed: datetime): raise KeyError(reso) grp = get_freq_group(reso) - iv = Period(parsed, freq=(grp, 1)) + iv = Period(parsed, freq=grp) return (iv.asfreq(self.freq, how="start"), iv.asfreq(self.freq, how="end")) def _validate_partial_date_slice(self, reso: str): From e7fb615247b2a0f9943802981cb881ab476a5a55 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 8 Jun 2020 17:47:30 -0700 Subject: [PATCH 2/2] whatsnew --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index c6ba196a8a985..e5e0b2577d595 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -403,6 +403,7 @@ Backwards incompatible API changes - :func:`read_excel` no longer takes ``**kwds`` arguments. This means that passing in keyword ``chunksize`` now raises a ``TypeError`` (previously raised a ``NotImplementedError``), while passing in keyword ``encoding`` now raises a ``TypeError`` (:issue:`34464`) - :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`) +- :class:`Period` no longer accepts tuples for the ``freq`` argument (:issue:`34658`) ``MultiIndex.get_indexer`` interprets `method` argument differently ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^