From 2105a166c75f878ba9785fe5544b9dff72bba72d Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Sat, 23 Sep 2023 00:19:42 +0200 Subject: [PATCH 01/15] add dictionary OFFSET_DEPR_FREQSTR, change warning msg --- pandas/_libs/tslibs/dtypes.pxd | 2 ++ pandas/_libs/tslibs/dtypes.pyi | 1 + pandas/_libs/tslibs/dtypes.pyx | 5 +++++ pandas/_libs/tslibs/offsets.pyx | 21 +++++++++++--------- pandas/tests/arrays/test_datetimes.py | 2 +- pandas/tests/frame/methods/test_asfreq.py | 2 +- pandas/tests/resample/test_datetime_index.py | 2 +- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pandas/_libs/tslibs/dtypes.pxd b/pandas/_libs/tslibs/dtypes.pxd index e050ac5a6c7b7..bda4fcf04234b 100644 --- a/pandas/_libs/tslibs/dtypes.pxd +++ b/pandas/_libs/tslibs/dtypes.pxd @@ -13,6 +13,8 @@ cpdef bint is_supported_unit(NPY_DATETIMEUNIT reso) cpdef freq_to_period_freqstr(freq_n, freq_name) cdef dict c_OFFSET_TO_PERIOD_FREQSTR +cdef dict c_OFFSET_DEPR_FREQSTR +cdef dict c_REVERSE_OFFSET_DEPR_FREQSTR cdef dict c_DEPR_ABBREVS cdef dict attrname_to_abbrevs cdef dict npy_unit_to_attrname diff --git a/pandas/_libs/tslibs/dtypes.pyi b/pandas/_libs/tslibs/dtypes.pyi index 72a8fa8ff0b38..d8680ed2d27b4 100644 --- a/pandas/_libs/tslibs/dtypes.pyi +++ b/pandas/_libs/tslibs/dtypes.pyi @@ -7,6 +7,7 @@ from pandas._libs.tslibs.timedeltas import UnitChoices _attrname_to_abbrevs: dict[str, str] _period_code_map: dict[str, int] OFFSET_TO_PERIOD_FREQSTR: dict[str, str] +OFFSET_DEPR_FREQSTR: dict[str, str] DEPR_ABBREVS: dict[str, UnitChoices] def periods_per_day(reso: int) -> int: ... diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx index cca379c620aeb..3dcbdd1300b0d 100644 --- a/pandas/_libs/tslibs/dtypes.pyx +++ b/pandas/_libs/tslibs/dtypes.pyx @@ -213,7 +213,12 @@ OFFSET_TO_PERIOD_FREQSTR: dict = { "YS": "A", "BYS": "A", } +OFFSET_DEPR_FREQSTR: dict[str, str]= { + "M": "ME", +} cdef dict c_OFFSET_TO_PERIOD_FREQSTR = OFFSET_TO_PERIOD_FREQSTR +cdef dict c_OFFSET_DEPR_FREQSTR = OFFSET_DEPR_FREQSTR +cdef dict c_REVERSE_OFFSET_DEPR_FREQSTR = {v: k for k, v in OFFSET_DEPR_FREQSTR.items()} cpdef freq_to_period_freqstr(freq_n, freq_name): if freq_n == 1: diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 74398eb0e2405..a35c5e9aa7406 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -57,6 +57,8 @@ from pandas._libs.tslibs.ccalendar cimport ( ) from pandas._libs.tslibs.conversion cimport localize_pydatetime from pandas._libs.tslibs.dtypes cimport ( + c_OFFSET_DEPR_FREQSTR, + c_REVERSE_OFFSET_DEPR_FREQSTR, c_DEPR_ABBREVS, periods_per_day, ) @@ -4615,21 +4617,22 @@ cpdef to_offset(freq, bint is_period=False): tups = zip(split[0::4], split[1::4], split[2::4]) for n, (sep, stride, name) in enumerate(tups): - if is_period is False and name == "M": + if is_period is False and name in c_OFFSET_DEPR_FREQSTR: warnings.warn( - "\'M\' will be deprecated, please use \'ME\' " - "for \'month end\'", + f"\'{name}\' will be deprecated, please use " + f"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' for Offsets.", UserWarning, stacklevel=find_stack_level(), ) - name = "ME" - if is_period is True and name == "ME": + name = c_OFFSET_DEPR_FREQSTR[name] + if is_period is True and name in c_REVERSE_OFFSET_DEPR_FREQSTR: raise ValueError( - r"for Period, please use \'M\' " - "instead of \'ME\'" + f"for Period, please use " + f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name)}\' " + f"instead of \'{name}\'" ) - elif is_period is True and name == "M": - name = "ME" + elif is_period is True and name in c_OFFSET_DEPR_FREQSTR: + name = c_OFFSET_DEPR_FREQSTR.get(name) if sep != "" and not sep.isspace(): raise ValueError("separator must be spaces") diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index a105852395b3a..593aca6cdd268 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -747,7 +747,7 @@ def test_iter_zoneinfo_fold(self, tz): assert left.utcoffset() == right2.utcoffset() def test_date_range_frequency_M_deprecated(self): - depr_msg = r"\'M\' will be deprecated, please use \'ME\' for \'month end\'" + depr_msg = f"'M' will be deprecated, please use 'ME' for Offsets." expected = pd.date_range("1/1/2000", periods=4, freq="2ME") with tm.assert_produces_warning(UserWarning, match=depr_msg): diff --git a/pandas/tests/frame/methods/test_asfreq.py b/pandas/tests/frame/methods/test_asfreq.py index a2f8f3e278395..f70810daf0dfd 100644 --- a/pandas/tests/frame/methods/test_asfreq.py +++ b/pandas/tests/frame/methods/test_asfreq.py @@ -235,7 +235,7 @@ def test_asfreq_2ME(self, freq, freq_half): tm.assert_frame_equal(result, expected) def test_asfreq_frequency_M_deprecated(self): - depr_msg = r"\'M\' will be deprecated, please use \'ME\' for \'month end\'" + depr_msg = f"'M' will be deprecated, please use 'ME' for Offsets." index = date_range("1/1/2000", periods=4, freq="ME") df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0], index=index)}) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index d929dfa6e1e59..93de385e387c3 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -2044,7 +2044,7 @@ def test_resample_empty_series_with_tz(): def test_resample_M_deprecated(): - depr_msg = r"\'M\' will be deprecated, please use \'ME\' for \'month end\'" + depr_msg = f"'M' will be deprecated, please use 'ME' for Offsets." s = Series(range(10), index=date_range("20130101", freq="d", periods=10)) expected = s.resample("2ME").mean() From 752fc87d13294b6825ad467a2e838011e778f96e Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Sat, 23 Sep 2023 10:38:40 +0200 Subject: [PATCH 02/15] rename Q to QE for offsets --- pandas/_libs/tslibs/dtypes.pyx | 3 ++- pandas/_libs/tslibs/offsets.pyx | 6 +++--- pandas/core/resample.py | 2 +- pandas/tests/indexes/period/test_period_range.py | 3 +++ pandas/tseries/frequencies.py | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx index 3dcbdd1300b0d..6601bf7473a6a 100644 --- a/pandas/_libs/tslibs/dtypes.pyx +++ b/pandas/_libs/tslibs/dtypes.pyx @@ -204,7 +204,7 @@ OFFSET_TO_PERIOD_FREQSTR: dict = { "us": "us", "ns": "ns", "H": "H", - "Q": "Q", + "QE": "Q", "A": "A", "W": "W", "ME": "M", @@ -214,6 +214,7 @@ OFFSET_TO_PERIOD_FREQSTR: dict = { "BYS": "A", } OFFSET_DEPR_FREQSTR: dict[str, str]= { + "Q": "QE", "M": "ME", } cdef dict c_OFFSET_TO_PERIOD_FREQSTR = OFFSET_TO_PERIOD_FREQSTR diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index a35c5e9aa7406..77abfc59c7bba 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2746,7 +2746,7 @@ cdef class QuarterEnd(QuarterOffset): Timestamp('2022-03-31 00:00:00') """ _default_starting_month = 3 - _prefix = "Q" + _prefix = "QE" _day_opt = "end" cdef readonly: @@ -4471,7 +4471,7 @@ prefix_mapping = { Second, # 's' Minute, # 'min' Micro, # 'us' - QuarterEnd, # 'Q' + QuarterEnd, # 'QE' QuarterBegin, # 'QS' Milli, # 'ms' Hour, # 'H' @@ -4489,7 +4489,7 @@ opattern = re.compile( _lite_rule_alias = { "W": "W-SUN", - "Q": "Q-DEC", + "QE": "QE-DEC", "A": "A-DEC", # YearEnd(month=12), "Y": "A-DEC", diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 30d654078bd05..25e2391e2b7df 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -2101,7 +2101,7 @@ def __init__( else: freq = to_offset(freq) - end_types = {"ME", "A", "Q", "BM", "BA", "BQ", "W"} + end_types = {"ME", "A", "QE", "BM", "BA", "BQ", "W"} rule = freq.rule_code if rule in end_types or ("-" in rule and rule[: rule.find("-")] in end_types): if closed is None: diff --git a/pandas/tests/indexes/period/test_period_range.py b/pandas/tests/indexes/period/test_period_range.py index 63acaba2d4f3e..4ad1ba2afe2f6 100644 --- a/pandas/tests/indexes/period/test_period_range.py +++ b/pandas/tests/indexes/period/test_period_range.py @@ -152,3 +152,6 @@ def test_period_range_frequency_ME_error_message(self): msg = "Invalid frequency: 2ME" with pytest.raises(ValueError, match=msg): period_range(start="Jan-2000", end="Dec-2000", freq="2ME") + + def test_my(self): + Period("2017Q1", freq="Q") diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index 7aa245341cbdd..ae08545236218 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -359,7 +359,7 @@ def _get_quarterly_rule(self) -> str | None: if pos_check is None: return None else: - return {"cs": "QS", "bs": "BQS", "ce": "Q", "be": "BQ"}.get(pos_check) + return {"cs": "QS", "bs": "BQS", "ce": "QE", "be": "BQ"}.get(pos_check) def _get_monthly_rule(self) -> str | None: if len(self.mdiffs) > 1: From 2c1b4367598dda28565ec70fd51938cda25a3d8d Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Mon, 16 Oct 2023 23:08:33 +0200 Subject: [PATCH 03/15] correct def _adjust_bin_edges, dicts OFFSET_DEPR_FREQSTR, OFFSET_TO_PERIOD_FREQSTR, fix tests --- pandas/_libs/tslibs/dtypes.pyx | 27 +++++++++-- pandas/_libs/tslibs/offsets.pyx | 2 - pandas/core/resample.py | 2 +- pandas/tests/arithmetic/test_datetime64.py | 2 +- pandas/tests/arrays/test_datetimelike.py | 2 +- pandas/tests/frame/test_nonunique_indexes.py | 2 +- pandas/tests/groupby/test_timegrouper.py | 2 +- .../datetimes/methods/test_to_period.py | 2 +- .../indexes/datetimes/test_constructors.py | 3 +- .../indexes/datetimes/test_date_range.py | 4 +- pandas/tests/indexes/datetimes/test_misc.py | 2 +- pandas/tests/indexes/datetimes/test_ops.py | 2 +- pandas/tests/indexes/datetimes/test_setops.py | 6 +-- .../tests/indexes/period/test_period_range.py | 30 +++++++----- .../tests/io/json/test_json_table_schema.py | 2 +- pandas/tests/plotting/test_converter.py | 2 +- pandas/tests/plotting/test_datetimelike.py | 12 ++--- pandas/tests/resample/test_datetime_index.py | 22 ++++----- pandas/tests/resample/test_period_index.py | 8 ++-- pandas/tests/scalar/period/test_period.py | 2 - .../tseries/frequencies/test_inference.py | 46 +++++++++---------- pandas/tests/tseries/offsets/test_offsets.py | 4 +- pandas/tests/tslibs/test_to_offset.py | 6 +-- 23 files changed, 109 insertions(+), 83 deletions(-) diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx index 11df3b400ce38..ac0b15dc73a8d 100644 --- a/pandas/_libs/tslibs/dtypes.pyx +++ b/pandas/_libs/tslibs/dtypes.pyx @@ -202,6 +202,18 @@ OFFSET_TO_PERIOD_FREQSTR: dict = { "ns": "ns", "h": "h", "QE": "Q", + "QE-DEC": "Q-DEC", + "QE-JAN": "Q-JAN", + "QE-FEB": "Q-FEB", + "QE-MAR": "Q-MAR", + "QE-APR": "Q-APR", + "QE-MAY": "Q-MAY", + "QE-JUN": "Q-JUN", + "QE-JUL": "Q-JUL", + "QE-AUG": "Q-AUG", + "QE-SEP": "Q-SEP", + "QE-OCT": "Q-OCT", + "QE-NOV": "Q-NOV", "W": "W", "ME": "M", "Y": "Y", @@ -211,10 +223,19 @@ OFFSET_TO_PERIOD_FREQSTR: dict = { } OFFSET_DEPR_FREQSTR: dict[str, str]= { "M": "ME", -} -OFFSET_DEPR_FREQSTR: dict[str, str]= { "Q": "QE", - "M": "ME", + "Q-DEC": "QE-DEC", + "Q-JAN": "QE-JAN", + "Q-FEB": "QE-FEB", + "Q-MAR": "QE-MAR", + "Q-APR": "QE-APR", + "Q-MAY": "QE-MAY", + "Q-JUN": "QE-JUN", + "Q-JUL": "QE-JUL", + "Q-AUG": "QE-AUG", + "Q-SEP": "QE-SEP", + "Q-OCT": "QE-OCT", + "Q-NOV": "QE-NOV", } cdef dict c_OFFSET_TO_PERIOD_FREQSTR = OFFSET_TO_PERIOD_FREQSTR cdef dict c_OFFSET_DEPR_FREQSTR = OFFSET_DEPR_FREQSTR diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 0417957530acd..82503a8c8bb7e 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -57,8 +57,6 @@ from pandas._libs.tslibs.ccalendar cimport ( ) from pandas._libs.tslibs.conversion cimport localize_pydatetime from pandas._libs.tslibs.dtypes cimport ( - c_OFFSET_DEPR_FREQSTR, - c_REVERSE_OFFSET_DEPR_FREQSTR, c_DEPR_ABBREVS, c_OFFSET_DEPR_FREQSTR, c_REVERSE_OFFSET_DEPR_FREQSTR, diff --git a/pandas/core/resample.py b/pandas/core/resample.py index ffab5edde54d4..b169c8cc06068 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -2300,7 +2300,7 @@ def _adjust_bin_edges( if self.freq.name in ("BME", "ME", "W") or self.freq.name.split("-")[0] in ( "BQ", "BY", - "Q", + "QE", "Y", "W", ): diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index 67bcafd583086..166832e8ecb3e 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -1076,7 +1076,7 @@ def test_dt64arr_add_dtlike_raises(self, tz_naive_fixture, box_with_array): # Note: freq here includes both Tick and non-Tick offsets; this is # relevant because historically integer-addition was allowed if we had # a freq. - @pytest.mark.parametrize("freq", ["h", "D", "W", "2ME", "MS", "Q", "B", None]) + @pytest.mark.parametrize("freq", ["h", "D", "W", "2ME", "MS", "QE", "B", None]) @pytest.mark.parametrize("dtype", [None, "uint8"]) def test_dt64arr_addsub_intlike( self, request, dtype, box_with_array, freq, tz_naive_fixture diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 3f91b9b03e1de..31bd4f7974c62 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -32,7 +32,7 @@ # TODO: more freq variants -@pytest.fixture(params=["D", "B", "W", "ME", "Q", "Y"]) +@pytest.fixture(params=["D", "B", "W", "ME", "QE", "Y"]) def freqstr(request): """Fixture returning parametrized frequency in string format.""" return request.param diff --git a/pandas/tests/frame/test_nonunique_indexes.py b/pandas/tests/frame/test_nonunique_indexes.py index 4f0d5ad5488c0..8f4b7d27e45f3 100644 --- a/pandas/tests/frame/test_nonunique_indexes.py +++ b/pandas/tests/frame/test_nonunique_indexes.py @@ -29,7 +29,7 @@ def test_setattr_columns_vs_construct_with_columns(self): check(df, expected) def test_setattr_columns_vs_construct_with_columns_datetimeindx(self): - idx = date_range("20130101", periods=4, freq="Q-NOV") + idx = date_range("20130101", periods=4, freq="QE-NOV") df = DataFrame( [[1, 1, 1, 5], [1, 1, 2, 5], [2, 1, 3, 5]], columns=["a", "a", "a", "a"] ) diff --git a/pandas/tests/groupby/test_timegrouper.py b/pandas/tests/groupby/test_timegrouper.py index 31629ba697e33..80860d5192857 100644 --- a/pandas/tests/groupby/test_timegrouper.py +++ b/pandas/tests/groupby/test_timegrouper.py @@ -336,7 +336,7 @@ def test_timegrouper_with_reg_groups(self): ) tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("freq", ["D", "ME", "Y", "Q-APR"]) + @pytest.mark.parametrize("freq", ["D", "ME", "Y", "QE-APR"]) def test_timegrouper_with_reg_groups_freq(self, freq): # GH 6764 multiple grouping with/without sort df = DataFrame( diff --git a/pandas/tests/indexes/datetimes/methods/test_to_period.py b/pandas/tests/indexes/datetimes/methods/test_to_period.py index d95cd6f3a2cc5..33ce915077ea5 100644 --- a/pandas/tests/indexes/datetimes/methods/test_to_period.py +++ b/pandas/tests/indexes/datetimes/methods/test_to_period.py @@ -54,7 +54,7 @@ def test_to_period_quarterly(self, month): def test_to_period_quarterlyish(self, off): rng = date_range("01-Jan-2012", periods=8, freq=off) prng = rng.to_period() - assert prng.freq == "Q-DEC" + assert prng.freq == "QE-DEC" @pytest.mark.parametrize("off", ["BY", "YS", "BYS"]) def test_to_period_annualish(self, off): diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 077b4fa5a0696..052e478fb2d12 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -1036,7 +1036,8 @@ def test_constructor_int64_nocopy(self): assert (index.asi8[50:100] != -1).all() @pytest.mark.parametrize( - "freq", ["ME", "Q", "Y", "D", "B", "bh", "min", "s", "ms", "us", "h", "ns", "C"] + "freq", + ["ME", "QE", "Y", "D", "B", "bh", "min", "s", "ms", "us", "h", "ns", "C"], ) def test_from_freq_recreate_from_data(self, freq): org = date_range(start="2001/02/01 09:00", freq=freq, periods=1) diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index a74d31747fbb0..86966b61fcd7f 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -965,7 +965,7 @@ def test_3(self): def test_precision_finer_than_offset(self): # GH#9907 result1 = date_range( - start="2015-04-15 00:00:03", end="2016-04-22 00:00:00", freq="Q" + start="2015-04-15 00:00:03", end="2016-04-22 00:00:00", freq="QE" ) result2 = date_range( start="2015-04-15 00:00:03", end="2015-06-22 00:00:04", freq="W" @@ -989,7 +989,7 @@ def test_precision_finer_than_offset(self): "2015-06-21 00:00:03", ] expected1 = DatetimeIndex( - expected1_list, dtype="datetime64[ns]", freq="Q-DEC", tz=None + expected1_list, dtype="datetime64[ns]", freq="QE-DEC", tz=None ) expected2 = DatetimeIndex( expected2_list, dtype="datetime64[ns]", freq="W-SUN", tz=None diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index d86d78ba47c5b..ce06fc35aabb1 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -142,7 +142,7 @@ def test_datetimeindex_accessors4(self): def test_datetimeindex_accessors5(self): freq_m = to_offset("ME") bm = to_offset("BME") - qfeb = to_offset("Q-FEB") + qfeb = to_offset("QE-FEB") qsfeb = to_offset("QS-FEB") bq = to_offset("BQ") bqs_apr = to_offset("BQS-APR") diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index c58d55ad6371b..60568c67096a9 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -21,7 +21,7 @@ class TestDatetimeIndexOps: "freq,expected", [ ("Y", "day"), - ("Q", "day"), + ("QE", "day"), ("ME", "day"), ("D", "day"), ("h", "hour"), diff --git a/pandas/tests/indexes/datetimes/test_setops.py b/pandas/tests/indexes/datetimes/test_setops.py index 6071c7fa8319b..6b50130a57c71 100644 --- a/pandas/tests/indexes/datetimes/test_setops.py +++ b/pandas/tests/indexes/datetimes/test_setops.py @@ -360,8 +360,8 @@ def test_difference_freq(self, sort): tm.assert_attr_equal("freq", idx_diff, expected) def test_datetimeindex_diff(self, sort): - dti1 = date_range(freq="Q-JAN", start=datetime(1997, 12, 31), periods=100) - dti2 = date_range(freq="Q-JAN", start=datetime(1997, 12, 31), periods=98) + dti1 = date_range(freq="QE-JAN", start=datetime(1997, 12, 31), periods=100) + dti2 = date_range(freq="QE-JAN", start=datetime(1997, 12, 31), periods=98) assert len(dti1.difference(dti2, sort)) == 2 @pytest.mark.parametrize("tz", [None, "Asia/Tokyo", "US/Eastern"]) @@ -410,7 +410,7 @@ def test_intersection_non_tick_no_fastpath(self): "2019-12-31", "2020-03-31", ], - freq="Q-DEC", + freq="QE-DEC", ) result = dti[::2].intersection(dti[1::2]) expected = dti[:0] diff --git a/pandas/tests/indexes/period/test_period_range.py b/pandas/tests/indexes/period/test_period_range.py index 3f78516ffbf28..c79515ae9f1d6 100644 --- a/pandas/tests/indexes/period/test_period_range.py +++ b/pandas/tests/indexes/period/test_period_range.py @@ -20,33 +20,41 @@ def test_required_arguments(self): with pytest.raises(ValueError, match=msg): period_range("2011-1-1", "2012-1-1", "B") - @pytest.mark.parametrize("freq", ["D", "W", "Q", "Y"]) - def test_construction_from_string(self, freq): + @pytest.mark.parametrize( + "freq_offset, freq_period", + [ + ("D", "D"), + ("W", "W"), + ("QE", "Q"), + ("Y", "Y"), + ], + ) + def test_construction_from_string(self, freq_offset, freq_period): # non-empty expected = date_range( - start="2017-01-01", periods=5, freq=freq, name="foo" + start="2017-01-01", periods=5, freq=freq_offset, name="foo" ).to_period() start, end = str(expected[0]), str(expected[-1]) - result = period_range(start=start, end=end, freq=freq, name="foo") + result = period_range(start=start, end=end, freq=freq_period, name="foo") tm.assert_index_equal(result, expected) - result = period_range(start=start, periods=5, freq=freq, name="foo") + result = period_range(start=start, periods=5, freq=freq_period, name="foo") tm.assert_index_equal(result, expected) - result = period_range(end=end, periods=5, freq=freq, name="foo") + result = period_range(end=end, periods=5, freq=freq_period, name="foo") tm.assert_index_equal(result, expected) # empty - expected = PeriodIndex([], freq=freq, name="foo") + expected = PeriodIndex([], freq=freq_period, name="foo") - result = period_range(start=start, periods=0, freq=freq, name="foo") + result = period_range(start=start, periods=0, freq=freq_period, name="foo") tm.assert_index_equal(result, expected) - result = period_range(end=end, periods=0, freq=freq, name="foo") + result = period_range(end=end, periods=0, freq=freq_period, name="foo") tm.assert_index_equal(result, expected) - result = period_range(start=end, end=start, freq=freq, name="foo") + result = period_range(start=end, end=start, freq=freq_period, name="foo") tm.assert_index_equal(result, expected) def test_construction_from_string_monthly(self): @@ -89,7 +97,7 @@ def test_construction_from_period(self): # downsampling start, end = Period("2017-1", freq="M"), Period("2019-12", freq="M") expected = date_range( - start="2017-01-31", end="2019-12-31", freq="Q", name="foo" + start="2017-01-31", end="2019-12-31", freq="QE", name="foo" ).to_period() result = period_range(start=start, end=end, freq="Q", name="foo") tm.assert_index_equal(result, expected) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 943515acd33b5..ef7ee8596d869 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -389,7 +389,7 @@ def test_to_json_period_index(self): result["schema"].pop("pandas_version") fields = [ - {"freq": "Q-JAN", "name": "index", "type": "datetime"}, + {"freq": "QE-JAN", "name": "index", "type": "datetime"}, {"name": "values", "type": "integer"}, ] diff --git a/pandas/tests/plotting/test_converter.py b/pandas/tests/plotting/test_converter.py index 7d574b86cef36..509e0ea5c482e 100644 --- a/pandas/tests/plotting/test_converter.py +++ b/pandas/tests/plotting/test_converter.py @@ -392,7 +392,7 @@ def test_quarterly_finder(year_span): pytest.skip("the quarterly finder is only invoked if the span is >= 45") nyears = span / 4 (min_anndef, maj_anndef) = converter._get_default_annual_spacing(nyears) - result = converter._quarterly_finder(vmin, vmax, to_offset("Q")) + result = converter._quarterly_finder(vmin, vmax, to_offset("QE")) quarters = PeriodIndex( arrays.PeriodArray(np.array([x[0] for x in result]), dtype="period[Q]") ) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index a384fd9cdc8f2..42f1a30983414 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -125,7 +125,7 @@ def test_tsplot_period(self, freq): _check_plot_works(ser.plot, ax=ax) @pytest.mark.parametrize( - "freq", ["s", "min", "h", "D", "W", "ME", "Q-DEC", "Y", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "Y", "1B30Min"] ) def test_tsplot_datetime(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -204,14 +204,14 @@ def test_line_plot_period_mlt_series(self, frqncy): _check_plot_works(s.plot, s.index.freq.rule_code) @pytest.mark.parametrize( - "freq", ["s", "min", "h", "D", "W", "ME", "Q-DEC", "Y", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "Y", "1B30Min"] ) def test_line_plot_datetime_series(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) ser = Series(np.random.default_rng(2).standard_normal(len(idx)), idx) _check_plot_works(ser.plot, ser.index.freq.rule_code) - @pytest.mark.parametrize("freq", ["s", "min", "h", "D", "W", "ME", "Q", "Y"]) + @pytest.mark.parametrize("freq", ["s", "min", "h", "D", "W", "ME", "QE", "Y"]) def test_line_plot_period_frame(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) df = DataFrame( @@ -240,7 +240,7 @@ def test_line_plot_period_mlt_frame(self, frqncy): @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") @pytest.mark.parametrize( - "freq", ["s", "min", "h", "D", "W", "ME", "Q-DEC", "Y", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "Y", "1B30Min"] ) def test_line_plot_datetime_frame(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -254,7 +254,7 @@ def test_line_plot_datetime_frame(self, freq): _check_plot_works(df.plot, freq) @pytest.mark.parametrize( - "freq", ["s", "min", "h", "D", "W", "ME", "Q-DEC", "Y", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "Y", "1B30Min"] ) def test_line_plot_inferred_freq(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -439,7 +439,7 @@ def test_get_finder(self): assert conv.get_finder(to_offset("B")) == conv._daily_finder assert conv.get_finder(to_offset("D")) == conv._daily_finder assert conv.get_finder(to_offset("ME")) == conv._monthly_finder - assert conv.get_finder(to_offset("Q")) == conv._quarterly_finder + assert conv.get_finder(to_offset("QE")) == conv._quarterly_finder assert conv.get_finder(to_offset("Y")) == conv._annual_finder assert conv.get_finder(to_offset("W")) == conv._daily_finder diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index e0ba7902a8a6c..c61b8abf8b238 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -644,7 +644,7 @@ def test_resample_dup_index(): df.iloc[3, :] = np.nan warning_msg = "DataFrame.resample with axis=1 is deprecated." with tm.assert_produces_warning(FutureWarning, match=warning_msg): - result = df.resample("Q", axis=1).mean() + result = df.resample("QE", axis=1).mean() msg = "DataFrame.groupby with axis=1 is deprecated" with tm.assert_produces_warning(FutureWarning, match=msg): @@ -1149,19 +1149,19 @@ def test_resample_anchored_intraday(simple_date_range_series, unit): rng = date_range("1/1/2012", "4/1/2012", freq="100min").as_unit(unit) df = DataFrame(rng.month, index=rng) - result = df.resample("Q").mean() - expected = df.resample("Q", kind="period").mean().to_timestamp(how="end") + result = df.resample("QE").mean() + expected = df.resample("QE", kind="period").mean().to_timestamp(how="end") expected.index += Timedelta(1, "ns") - Timedelta(1, "D") - expected.index._data.freq = "Q" + expected.index._data.freq = "QE" expected.index._freq = lib.no_default expected.index = expected.index.as_unit(unit) tm.assert_frame_equal(result, expected) - result = df.resample("Q", closed="left").mean() - expected = df.shift(1, freq="D").resample("Q", kind="period", closed="left").mean() + result = df.resample("QE", closed="left").mean() + expected = df.shift(1, freq="D").resample("QE", kind="period", closed="left").mean() expected = expected.to_timestamp(how="end") expected.index += Timedelta(1, "ns") - Timedelta(1, "D") - expected.index._data.freq = "Q" + expected.index._data.freq = "QE" expected.index._freq = lib.no_default expected.index = expected.index.as_unit(unit) tm.assert_frame_equal(result, expected) @@ -1871,11 +1871,11 @@ def test_resample_apply_product(duplicates, unit): msg = "using DatetimeIndexResampler.prod" with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.resample("Q").apply(np.prod) + result = df.resample("QE").apply(np.prod) expected = DataFrame( np.array([[0, 24], [60, 210], [336, 720], [990, 1716]], dtype=np.int64), index=DatetimeIndex( - ["2012-03-31", "2012-06-30", "2012-09-30", "2012-12-31"], freq="Q-DEC" + ["2012-03-31", "2012-06-30", "2012-09-30", "2012-12-31"], freq="QE-DEC" ).as_unit(unit), columns=df.columns, ) @@ -1937,10 +1937,10 @@ def test_resample_aggregate_functions_min_count(func, unit): # GH#37768 index = date_range(start="2020", freq="ME", periods=3).as_unit(unit) ser = Series([1, np.nan, np.nan], index) - result = getattr(ser.resample("Q"), func)(min_count=2) + result = getattr(ser.resample("QE"), func)(min_count=2) expected = Series( [np.nan], - index=DatetimeIndex(["2020-03-31"], freq="Q-DEC").as_unit(unit), + index=DatetimeIndex(["2020-03-31"], freq="QE-DEC").as_unit(unit), ) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 6ad09f12525b4..6e21efa7e1885 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -134,7 +134,7 @@ def test_basic_downsample(self, simple_period_range_series): "rule,expected_error_msg", [ ("y-dec", ""), - ("q-mar", ""), + ("qe-mar", ""), ("M", ""), ("w-thu", ""), ], @@ -367,7 +367,7 @@ def test_fill_method_and_how_upsample(self): # GH2073 s = Series( np.arange(9, dtype="int64"), - index=date_range("2010-01-01", periods=9, freq="Q"), + index=date_range("2010-01-01", periods=9, freq="QE"), ) last = s.resample("ME").ffill() both = s.resample("ME").ffill().resample("ME").last().astype("int64") @@ -647,7 +647,7 @@ def test_monthly_convention_span(self): tm.assert_series_equal(result, expected) @pytest.mark.parametrize( - "from_freq, to_freq", [("D", "ME"), ("Q", "Y"), ("ME", "Q"), ("D", "W")] + "from_freq, to_freq", [("D", "ME"), ("QE", "Y"), ("ME", "QE"), ("D", "W")] ) def test_default_right_closed_label(self, from_freq, to_freq): idx = date_range(start="8/15/2012", periods=100, freq=from_freq) @@ -660,7 +660,7 @@ def test_default_right_closed_label(self, from_freq, to_freq): @pytest.mark.parametrize( "from_freq, to_freq", - [("D", "MS"), ("Q", "YS"), ("ME", "QS"), ("h", "D"), ("min", "h")], + [("D", "MS"), ("QE", "YS"), ("ME", "QS"), ("h", "D"), ("min", "h")], ) def test_default_left_closed_label(self, from_freq, to_freq): idx = date_range(start="8/15/2012", periods=100, freq=from_freq) diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index dc2938ec345f3..0beea04f2f0ae 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -73,10 +73,8 @@ def test_construction(self): i1 = Period.now(freq="Q") i2 = Period(datetime.now(), freq="Q") - i3 = Period.now("q") assert i1 == i2 - assert i1 == i3 # Pass in freq as a keyword argument sometimes as a test for # https://github.com/pandas-dev/pandas/issues/53369 diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index aec9915d69e3c..ea87f4dbd017d 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -51,7 +51,7 @@ def base_delta_code_pair(request): freqs = ( - [f"Q-{month}" for month in MONTHS] + [f"QE-{month}" for month in MONTHS] + [f"{annual}-{month}" for annual in ["Y", "BY"] for month in MONTHS] + ["ME", "BME", "BMS"] + [f"WOM-{count}{day}" for count in range(1, 5) for day in DAYS] @@ -67,28 +67,28 @@ def test_infer_freq_range(periods, freq): gen = date_range("1/1/2000", periods=periods, freq=freq) index = DatetimeIndex(gen.values) - if not freq.startswith("Q-"): + if not freq.startswith("QE-"): assert frequencies.infer_freq(index) == gen.freqstr else: inf_freq = frequencies.infer_freq(index) - is_dec_range = inf_freq == "Q-DEC" and gen.freqstr in ( - "Q", - "Q-DEC", - "Q-SEP", - "Q-JUN", - "Q-MAR", + is_dec_range = inf_freq == "QE-DEC" and gen.freqstr in ( + "QE", + "QE-DEC", + "QE-SEP", + "QE-JUN", + "QE-MAR", ) - is_nov_range = inf_freq == "Q-NOV" and gen.freqstr in ( - "Q-NOV", - "Q-AUG", - "Q-MAY", - "Q-FEB", + is_nov_range = inf_freq == "QE-NOV" and gen.freqstr in ( + "QE-NOV", + "QE-AUG", + "QE-MAY", + "QE-FEB", ) - is_oct_range = inf_freq == "Q-OCT" and gen.freqstr in ( - "Q-OCT", - "Q-JUL", - "Q-APR", - "Q-JAN", + is_oct_range = inf_freq == "QE-OCT" and gen.freqstr in ( + "QE-OCT", + "QE-JUL", + "QE-APR", + "QE-JAN", ) assert is_dec_range or is_nov_range or is_oct_range @@ -202,7 +202,7 @@ def test_infer_freq_custom(base_delta_code_pair, constructor): @pytest.mark.parametrize( - "freq,expected", [("Q", "Q-DEC"), ("Q-NOV", "Q-NOV"), ("Q-OCT", "Q-OCT")] + "freq,expected", [("Q", "QE-DEC"), ("Q-NOV", "QE-NOV"), ("Q-OCT", "QE-OCT")] ) def test_infer_freq_index(freq, expected): rng = period_range("1959Q2", "2009Q3", freq=freq) @@ -216,7 +216,7 @@ def test_infer_freq_index(freq, expected): list( { "YS-JAN": ["2009-01-01", "2010-01-01", "2011-01-01", "2012-01-01"], - "Q-OCT": ["2009-01-31", "2009-04-30", "2009-07-31", "2009-10-31"], + "QE-OCT": ["2009-01-31", "2009-04-30", "2009-07-31", "2009-10-31"], "ME": ["2010-11-30", "2010-12-31", "2011-01-31", "2011-02-28"], "W-SAT": ["2010-12-25", "2011-01-01", "2011-01-08", "2011-01-15"], "D": ["2011-01-01", "2011-01-02", "2011-01-03", "2011-01-04"], @@ -476,9 +476,9 @@ def test_series_datetime_index(freq): "W@FRI", "W@SAT", "W@SUN", - "Q@JAN", - "Q@FEB", - "Q@MAR", + "QE@JAN", + "QE@FEB", + "QE@MAR", "Y@JAN", "Y@FEB", "Y@MAR", diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 7cefd93851b0e..725013e2a7b43 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -839,7 +839,7 @@ def test_rule_code(self): "NOV", "DEC", ] - base_lst = ["Y", "YS", "BY", "BYS", "Q", "QS", "BQ", "BQS"] + base_lst = ["Y", "YS", "BY", "BYS", "QE", "QS", "BQ", "BQS"] for base in base_lst: for v in suffix_lst: alias = "-".join([base, v]) @@ -858,7 +858,7 @@ def test_freq_offsets(): class TestReprNames: def test_str_for_named_is_name(self): # look at all the amazing combinations! - month_prefixes = ["Y", "YS", "BY", "BYS", "Q", "BQ", "BQS", "QS"] + month_prefixes = ["Y", "YS", "BY", "BYS", "QE", "BQ", "BQS", "QS"] names = [ prefix + "-" + month for prefix in month_prefixes diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index 82b0c78002972..3fb205f21a857 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -158,9 +158,9 @@ def test_to_offset_pd_timedelta(kwargs, expected): [ ("W", offsets.Week(weekday=6)), ("W-SUN", offsets.Week(weekday=6)), - ("Q", offsets.QuarterEnd(startingMonth=12)), - ("Q-DEC", offsets.QuarterEnd(startingMonth=12)), - ("Q-MAY", offsets.QuarterEnd(startingMonth=5)), + ("QE", offsets.QuarterEnd(startingMonth=12)), + ("QE-DEC", offsets.QuarterEnd(startingMonth=12)), + ("QE-MAY", offsets.QuarterEnd(startingMonth=5)), ("SM", offsets.SemiMonthEnd(day_of_month=15)), ("SM-15", offsets.SemiMonthEnd(day_of_month=15)), ("SM-1", offsets.SemiMonthEnd(day_of_month=1)), From 8c563a51bcb1394a3bb4b54275fe706ccfae5b5a Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 17 Oct 2023 17:55:08 +0200 Subject: [PATCH 04/15] correct def convert_json_field_to_pandas_type --- pandas/io/json/_table_schema.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/io/json/_table_schema.py b/pandas/io/json/_table_schema.py index 3f2291ba7a0c3..bbe7f4533a484 100644 --- a/pandas/io/json/_table_schema.py +++ b/pandas/io/json/_table_schema.py @@ -15,6 +15,7 @@ from pandas._libs import lib from pandas._libs.json import ujson_loads from pandas._libs.tslibs import timezones +from pandas._libs.tslibs.dtypes import freq_to_period_freqstr from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.base import _registry as registry @@ -207,6 +208,7 @@ def convert_json_field_to_pandas_type(field) -> str | CategoricalDtype: if field.get("tz"): return f"datetime64[ns, {field['tz']}]" elif field.get("freq"): + field['freq'] = freq_to_period_freqstr(1, field['freq']) # GH#47747 using datetime over period to minimize the change surface return f"period[{field['freq']}]" else: From cb101a0b1b5160bb81e8b82cbde224f5bac0370a Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 18 Oct 2023 23:16:00 +0200 Subject: [PATCH 05/15] correct doc --- doc/source/user_guide/timeseries.rst | 6 +++--- doc/source/whatsnew/v0.18.0.rst | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 7ffbd9b2d740a..6141d9e604348 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -890,7 +890,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ :class:`~pandas.tseries.offsets.CBMonthBegin` or :class:`~pandas.tseries.offsets.CustomBusinessMonthBegin`, ``'CBMS'``, "custom business month begin" :class:`~pandas.tseries.offsets.SemiMonthEnd`, ``'SM'``, "15th (or other day_of_month) and calendar month end" :class:`~pandas.tseries.offsets.SemiMonthBegin`, ``'SMS'``, "15th (or other day_of_month) and calendar month begin" - :class:`~pandas.tseries.offsets.QuarterEnd`, ``'Q'``, "calendar quarter end" + :class:`~pandas.tseries.offsets.QuarterEnd`, ``'QE'``, "calendar quarter end" :class:`~pandas.tseries.offsets.QuarterBegin`, ``'QS'``, "calendar quarter begin" :class:`~pandas.tseries.offsets.BQuarterEnd`, ``'BQ``, "business quarter end" :class:`~pandas.tseries.offsets.BQuarterBegin`, ``'BQS'``, "business quarter begin" @@ -1254,7 +1254,7 @@ frequencies. We will refer to these aliases as *offset aliases*. "SMS", "semi-month start frequency (1st and 15th)" "BMS", "business month start frequency" "CBMS", "custom business month start frequency" - "Q", "quarter end frequency" + "QE", "quarter end frequency" "BQ", "business quarter end frequency" "QS", "quarter start frequency" "BQS", "business quarter start frequency" @@ -1692,7 +1692,7 @@ the end of the interval. .. warning:: The default values for ``label`` and ``closed`` is '**left**' for all - frequency offsets except for 'ME', 'Y', 'Q', 'BME', 'BY', 'BQ', and 'W' + frequency offsets except for 'ME', 'Y', 'QE', 'BME', 'BY', 'BQ', and 'W' which all have a default of 'right'. This might unintendedly lead to looking ahead, where the value for a later diff --git a/doc/source/whatsnew/v0.18.0.rst b/doc/source/whatsnew/v0.18.0.rst index 8984109da2a43..569197fe9daf5 100644 --- a/doc/source/whatsnew/v0.18.0.rst +++ b/doc/source/whatsnew/v0.18.0.rst @@ -808,11 +808,19 @@ Upsampling operations take you from a lower frequency to a higher frequency. The performed with the ``Resampler`` objects with :meth:`~Resampler.backfill`, :meth:`~Resampler.ffill`, :meth:`~Resampler.fillna` and :meth:`~Resampler.asfreq` methods. -.. ipython:: python +.. code-block:: ipython - s = pd.Series(np.arange(5, dtype='int64'), + In [89]: s = pd.Series(np.arange(5, dtype='int64'), index=pd.date_range('2010-01-01', periods=5, freq='Q')) - s + + In [90]: s + Out[90]: + 2010-03-31 0 + 2010-06-30 1 + 2010-09-30 2 + 2010-12-31 3 + 2011-03-31 4 + Freq: Q-DEC, Length: 5, dtype: int64 Previously From 477071c35fcb9c22d922b1e3ec68d0b8d7f419a3 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 19 Oct 2023 17:46:22 +0200 Subject: [PATCH 06/15] add tests, correct user_guide/timeseries.rst --- doc/source/user_guide/timeseries.rst | 24 +++++++++---------- pandas/io/json/_table_schema.py | 3 ++- pandas/tests/arrays/test_datetimes.py | 19 +++++++++++---- pandas/tests/frame/methods/test_asfreq.py | 21 ++++++++++++---- .../datetimes/methods/test_to_period.py | 17 +++++++++++++ pandas/tests/indexes/period/test_period.py | 8 +++++++ pandas/tests/resample/test_datetime_index.py | 17 +++++++++---- pandas/tests/resample/test_period_index.py | 10 ++++---- 8 files changed, 89 insertions(+), 30 deletions(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 6141d9e604348..c78921655eb05 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -1373,18 +1373,18 @@ For some frequencies you can specify an anchoring suffix: "W\-THU", "weekly frequency (Thursdays)" "W\-FRI", "weekly frequency (Fridays)" "W\-SAT", "weekly frequency (Saturdays)" - "(B)Q(S)\-DEC", "quarterly frequency, year ends in December. Same as 'Q'" - "(B)Q(S)\-JAN", "quarterly frequency, year ends in January" - "(B)Q(S)\-FEB", "quarterly frequency, year ends in February" - "(B)Q(S)\-MAR", "quarterly frequency, year ends in March" - "(B)Q(S)\-APR", "quarterly frequency, year ends in April" - "(B)Q(S)\-MAY", "quarterly frequency, year ends in May" - "(B)Q(S)\-JUN", "quarterly frequency, year ends in June" - "(B)Q(S)\-JUL", "quarterly frequency, year ends in July" - "(B)Q(S)\-AUG", "quarterly frequency, year ends in August" - "(B)Q(S)\-SEP", "quarterly frequency, year ends in September" - "(B)Q(S)\-OCT", "quarterly frequency, year ends in October" - "(B)Q(S)\-NOV", "quarterly frequency, year ends in November" + "(B)Q(E)(S)\-DEC", "quarterly frequency, year ends in December. Same as 'QE'" + "(B)Q(E)(S)\-JAN", "quarterly frequency, year ends in January" + "(B)Q(E)(S)\-FEB", "quarterly frequency, year ends in February" + "(B)Q(E)(S)\-MAR", "quarterly frequency, year ends in March" + "(B)Q(E)(S)\-APR", "quarterly frequency, year ends in April" + "(B)Q(E)(S)\-MAY", "quarterly frequency, year ends in May" + "(B)Q(E)(S)\-JUN", "quarterly frequency, year ends in June" + "(B)Q(E)(S)\-JUL", "quarterly frequency, year ends in July" + "(B)Q(E)(S)\-AUG", "quarterly frequency, year ends in August" + "(B)Q(E)(S)\-SEP", "quarterly frequency, year ends in September" + "(B)Q(E)(S)\-OCT", "quarterly frequency, year ends in October" + "(B)Q(E)(S)\-NOV", "quarterly frequency, year ends in November" "(B)Y(S)\-DEC", "annual frequency, anchored end of December. Same as 'Y'" "(B)Y(S)\-JAN", "annual frequency, anchored end of January" "(B)Y(S)\-FEB", "annual frequency, anchored end of February" diff --git a/pandas/io/json/_table_schema.py b/pandas/io/json/_table_schema.py index bbe7f4533a484..fa662c285e3e4 100644 --- a/pandas/io/json/_table_schema.py +++ b/pandas/io/json/_table_schema.py @@ -208,7 +208,8 @@ def convert_json_field_to_pandas_type(field) -> str | CategoricalDtype: if field.get("tz"): return f"datetime64[ns, {field['tz']}]" elif field.get("freq"): - field['freq'] = freq_to_period_freqstr(1, field['freq']) + # GH#9586 rename frequency M to ME for offsets + field["freq"] = freq_to_period_freqstr(1, field["freq"]) # GH#47747 using datetime over period to minimize the change surface return f"period[{field['freq']}]" else: diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index fc46e5a372806..3072e7aa0d4e9 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -746,12 +746,23 @@ def test_iter_zoneinfo_fold(self, tz): assert str(left) == str(right2) assert left.utcoffset() == right2.utcoffset() - def test_date_range_frequency_M_deprecated(self): - depr_msg = "'M' will be deprecated, please use 'ME' instead." + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2ME", "2M"), + ("2QE", "2Q"), + ("2QE-SEP", "2Q-SEP"), + ], + ) + def test_date_range_frequency_M_Q_deprecated(self, freq, freq_depr): + # GH#9586 + depr_msg = ( + f"'{freq_depr[1:]}' will be deprecated, please use '{freq[1:]}' instead." + ) - expected = pd.date_range("1/1/2000", periods=4, freq="2ME") + expected = pd.date_range("1/1/2000", periods=4, freq=freq) with tm.assert_produces_warning(UserWarning, match=depr_msg): - result = pd.date_range("1/1/2000", periods=4, freq="2M") + result = pd.date_range("1/1/2000", periods=4, freq=freq_depr) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_asfreq.py b/pandas/tests/frame/methods/test_asfreq.py index bc6e74d5b1f00..b155eff0c0e49 100644 --- a/pandas/tests/frame/methods/test_asfreq.py +++ b/pandas/tests/frame/methods/test_asfreq.py @@ -234,12 +234,23 @@ def test_asfreq_2ME(self, freq, freq_half): result = DataFrame({"s": Series([0.0, 2.0, 4.0], index=index)}) tm.assert_frame_equal(result, expected) - def test_asfreq_frequency_M_deprecated(self): - depr_msg = "'M' will be deprecated, please use 'ME' instead." + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2ME", "2M"), + ("2QE", "2Q"), + ("2QE-SEP", "2Q-SEP"), + ], + ) + def test_asfreq_frequency_M_Q_deprecated(sel, freq, freq_depr): + # GH#9586 + depr_msg = ( + f"'{freq_depr[1:]}' will be deprecated, please use '{freq[1:]}' instead." + ) - index = date_range("1/1/2000", periods=4, freq="ME") + index = date_range("1/1/2000", periods=4, freq=f"{freq[1:]}") df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0], index=index)}) - expected = df.asfreq(freq="5ME") + expected = df.asfreq(freq=freq) with tm.assert_produces_warning(UserWarning, match=depr_msg): - result = df.asfreq(freq="5M") + result = df.asfreq(freq=freq_depr) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/indexes/datetimes/methods/test_to_period.py b/pandas/tests/indexes/datetimes/methods/test_to_period.py index 33ce915077ea5..0a4848653d07c 100644 --- a/pandas/tests/indexes/datetimes/methods/test_to_period.py +++ b/pandas/tests/indexes/datetimes/methods/test_to_period.py @@ -89,6 +89,23 @@ def test_dti_to_period_2monthish(self, freq_offset, freq_period): tm.assert_index_equal(pi, period_range("2020-01", "2020-05", freq=freq_period)) + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2ME", "2M"), + ("2QE", "2Q"), + ("2QE-SEP", "2Q-SEP"), + ], + ) + def test_to_period_freq_deprecated(self, freq, freq_depr): + # GH#9586 + msg = f"'{freq_depr[1:]}' will be deprecated, please use '{freq[1:]}' instead." + + rng = date_range("01-Jan-2012", periods=8, freq=freq) + prng = rng.to_period() + with tm.assert_produces_warning(UserWarning, match=msg): + assert prng.freq == freq_depr + def test_to_period_infer(self): # https://github.com/pandas-dev/pandas/issues/33358 rng = date_range( diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 1bb8d66332cd0..84b8c55f3f0fa 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -307,6 +307,14 @@ def test_a_deprecated_from_time_series(self, freq): series = Series(1, index=index) assert isinstance(series, Series) + @pytest.mark.parametrize("freq_depr", ["2ME", "2QE"]) + def test_period_index_frequency_error_message(self, freq_depr): + # GH#9586 + msg = f"Invalid frequency: {freq_depr}" + + with pytest.raises(ValueError, match=msg): + period_range("2020-01", "2020-05", freq=freq_depr) + def test_maybe_convert_timedelta(): pi = PeriodIndex(["2000", "2001"], freq="D") diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index c61b8abf8b238..a7f38095ad6b2 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -2010,13 +2010,22 @@ def test_resample_empty_series_with_tz(): tm.assert_series_equal(result, expected) -def test_resample_M_deprecated(): - depr_msg = "'M' will be deprecated, please use 'ME' instead." +@pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2ME", "2M"), + ("2QE", "2Q"), + ("2QE-SEP", "2Q-SEP"), + ], +) +def test_resample_M_Q_deprecated(freq, freq_depr): + # GH#9586 + depr_msg = f"'{freq_depr[1:]}' will be deprecated, please use '{freq[1:]}' instead." s = Series(range(10), index=date_range("20130101", freq="d", periods=10)) - expected = s.resample("2ME").mean() + expected = s.resample(freq).mean() with tm.assert_produces_warning(UserWarning, match=depr_msg): - result = s.resample("2M").mean() + result = s.resample(freq_depr).mean() tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 6e21efa7e1885..e768d9266ab89 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -104,7 +104,7 @@ def test_selection(self, index, freq, kind, kwargs): @pytest.mark.parametrize("meth", ["ffill", "bfill"]) @pytest.mark.parametrize("conv", ["start", "end"]) @pytest.mark.parametrize( - ("offset", "period"), [("D", "D"), ("B", "B"), ("ME", "M")] + ("offset", "period"), [("D", "D"), ("B", "B"), ("ME", "M"), ("QE", "Q")] ) def test_annual_upsample_cases( self, offset, period, conv, meth, month, simple_period_range_series @@ -931,9 +931,11 @@ def test_resample_t_l_deprecated(self): tm.assert_series_equal(result, expected) -def test_resample_frequency_ME_error_message(series_and_frame): - msg = "Invalid frequency: 2ME" +@pytest.mark.parametrize("freq_depr", ["2ME", "2QE", "2QE-FEB"]) +def test_resample_frequency_ME_QE_error_message(series_and_frame, freq_depr): + # GH#9586 + msg = f"Invalid frequency: {freq_depr}" obj = series_and_frame with pytest.raises(ValueError, match=msg): - obj.resample("2ME") + obj.resample(freq_depr) From f1b7b29819236168c222862542583fd8c6d51d3a Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 19 Oct 2023 19:18:03 +0200 Subject: [PATCH 07/15] fix pylint failure --- pandas/tests/frame/methods/test_asfreq.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/methods/test_asfreq.py b/pandas/tests/frame/methods/test_asfreq.py index b155eff0c0e49..1962c25f9396e 100644 --- a/pandas/tests/frame/methods/test_asfreq.py +++ b/pandas/tests/frame/methods/test_asfreq.py @@ -242,7 +242,7 @@ def test_asfreq_2ME(self, freq, freq_half): ("2QE-SEP", "2Q-SEP"), ], ) - def test_asfreq_frequency_M_Q_deprecated(sel, freq, freq_depr): + def test_asfreq_frequency_M_Q_deprecated(self, freq, freq_depr): # GH#9586 depr_msg = ( f"'{freq_depr[1:]}' will be deprecated, please use '{freq[1:]}' instead." @@ -253,4 +253,4 @@ def test_asfreq_frequency_M_Q_deprecated(sel, freq, freq_depr): expected = df.asfreq(freq=freq) with tm.assert_produces_warning(UserWarning, match=depr_msg): result = df.asfreq(freq=freq_depr) - tm.assert_frame_equal(result, expected) + tm.assert_frame_equal(result, expected) From 0e89af94910c77e4cc81659909bb75f33e43500b Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 19 Oct 2023 21:06:41 +0200 Subject: [PATCH 08/15] correct docstring --- pandas/core/indexes/accessors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index d90de383adb48..f872b9eda4749 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -284,7 +284,7 @@ class DatetimeProperties(Properties): 2 2 dtype: int32 - >>> quarters_series = pd.Series(pd.date_range("2000-01-01", periods=3, freq="q")) + >>> quarters_series = pd.Series(pd.date_range("2000-01-01", periods=3, freq="qe")) >>> quarters_series 0 2000-03-31 1 2000-06-30 From 35db1b2a228fba3af250558cc8be57dce9b9510a Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Fri, 20 Oct 2023 13:37:05 +0200 Subject: [PATCH 09/15] add a note to v2.2.0.rst --- doc/source/whatsnew/v2.2.0.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index c8c27f2f2e178..43bc8caa12586 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -232,6 +232,28 @@ For example: pd.date_range('2020-01-01', periods=3, freq='ME') +Deprecate alias ``Q`` in favour of ``QE`` for offsets +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The alias ``Q`` is deprecated in favour of ``QE`` for offsets, please use ``QE`` for "quarter end" instead of ``Q`` (:issue:`9586`) + +For example: + +*Previous behavior*: + +.. code-block:: ipython + + In [8]: pd.date_range('2020-01-01', periods=3, freq='Q-NOV') + Out[8]: + DatetimeIndex(['2020-02-29', '2020-05-31', '2020-08-31'], + dtype='datetime64[ns]', freq='Q-NOV') + +*Future behavior*: + +.. ipython:: python + + pd.date_range('2020-01-01', periods=3, freq='QE-NOV') + Other Deprecations ^^^^^^^^^^^^^^^^^^ - Changed :meth:`Timedelta.resolution_string` to return ``h``, ``min``, ``s``, ``ms``, ``us``, and ``ns`` instead of ``H``, ``T``, ``S``, ``L``, ``U``, and ``N``, for compatibility with respective deprecations in frequency aliases (:issue:`52536`) From de976e124ff7f3363b0ee29786bd2ba4649f56dc Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Sat, 21 Oct 2023 16:05:49 +0200 Subject: [PATCH 10/15] remove test_my --- pandas/tests/indexes/period/test_period_range.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/tests/indexes/period/test_period_range.py b/pandas/tests/indexes/period/test_period_range.py index c79515ae9f1d6..e908cda449ee6 100644 --- a/pandas/tests/indexes/period/test_period_range.py +++ b/pandas/tests/indexes/period/test_period_range.py @@ -160,6 +160,3 @@ def test_period_range_frequency_ME_error_message(self): msg = "Invalid frequency: 2ME" with pytest.raises(ValueError, match=msg): period_range(start="Jan-2000", end="Dec-2000", freq="2ME") - - def test_my(self): - Period("2017Q1", freq="Q") From 55c99b5d7395b4531e08c9c94cdfe3f4c592176c Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Mon, 23 Oct 2023 18:13:51 +0200 Subject: [PATCH 11/15] fix tests --- pandas/tests/indexes/datetimes/methods/test_resolution.py | 2 +- pandas/tests/indexes/datetimes/methods/test_to_period.py | 2 +- pandas/tests/tseries/offsets/test_offsets.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/indexes/datetimes/methods/test_resolution.py b/pandas/tests/indexes/datetimes/methods/test_resolution.py index 6336fc8277947..5dcf2ad2a5a80 100644 --- a/pandas/tests/indexes/datetimes/methods/test_resolution.py +++ b/pandas/tests/indexes/datetimes/methods/test_resolution.py @@ -10,7 +10,7 @@ "freq,expected", [ ("Y", "day"), - ("Q", "day"), + ("QE", "day"), ("ME", "day"), ("D", "day"), ("h", "hour"), diff --git a/pandas/tests/indexes/datetimes/methods/test_to_period.py b/pandas/tests/indexes/datetimes/methods/test_to_period.py index 0a4848653d07c..c6fbf0f8d4489 100644 --- a/pandas/tests/indexes/datetimes/methods/test_to_period.py +++ b/pandas/tests/indexes/datetimes/methods/test_to_period.py @@ -103,7 +103,7 @@ def test_to_period_freq_deprecated(self, freq, freq_depr): rng = date_range("01-Jan-2012", periods=8, freq=freq) prng = rng.to_period() - with tm.assert_produces_warning(UserWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): assert prng.freq == freq_depr def test_to_period_infer(self): diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index a4abd469d69a4..c46c0ddfdc201 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -1120,7 +1120,7 @@ def test_dateoffset_operations_on_dataframes(): def test_is_yqm_start_end(): freq_m = to_offset("ME") bm = to_offset("BME") - qfeb = to_offset("Q-FEB") + qfeb = to_offset("QE-FEB") qsfeb = to_offset("QS-FEB") bq = to_offset("BQ") bqs_apr = to_offset("BQS-APR") From e563d6bb682748aa93a21e7bde65f9201a0f5b43 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Mon, 23 Oct 2023 21:33:29 +0200 Subject: [PATCH 12/15] roll back my changes in convert_json_field_to_pandas_type, correct v2.2.0.rst --- doc/source/whatsnew/v2.2.0.rst | 7 ++----- pandas/io/json/_table_schema.py | 3 --- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 2201bbf1fb574..6b8c4f25a8b76 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -210,8 +210,8 @@ Other API changes Deprecations ~~~~~~~~~~~~ -Deprecate alias ``M`` in favour of ``ME`` for offsets -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Deprecate aliases ``M`` and ``Q`` in favour of ``ME`` and ``QE`` for offsets +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The alias ``M`` is deprecated in favour of ``ME`` for offsets, please use ``ME`` for "month end" instead of ``M`` (:issue:`9586`) @@ -232,9 +232,6 @@ For example: pd.date_range('2020-01-01', periods=3, freq='ME') -Deprecate alias ``Q`` in favour of ``QE`` for offsets -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - The alias ``Q`` is deprecated in favour of ``QE`` for offsets, please use ``QE`` for "quarter end" instead of ``Q`` (:issue:`9586`) For example: diff --git a/pandas/io/json/_table_schema.py b/pandas/io/json/_table_schema.py index fa662c285e3e4..3f2291ba7a0c3 100644 --- a/pandas/io/json/_table_schema.py +++ b/pandas/io/json/_table_schema.py @@ -15,7 +15,6 @@ from pandas._libs import lib from pandas._libs.json import ujson_loads from pandas._libs.tslibs import timezones -from pandas._libs.tslibs.dtypes import freq_to_period_freqstr from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.base import _registry as registry @@ -208,8 +207,6 @@ def convert_json_field_to_pandas_type(field) -> str | CategoricalDtype: if field.get("tz"): return f"datetime64[ns, {field['tz']}]" elif field.get("freq"): - # GH#9586 rename frequency M to ME for offsets - field["freq"] = freq_to_period_freqstr(1, field["freq"]) # GH#47747 using datetime over period to minimize the change surface return f"period[{field['freq']}]" else: From 15cfdb18340e0add3c7bb3c869a432b651112911 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 24 Oct 2023 10:28:17 +0200 Subject: [PATCH 13/15] add 'qe' to _dont_uppercase --- pandas/_libs/tslibs/offsets.pyx | 2 +- pandas/tests/scalar/period/test_period.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 63a5808339907..45188c536d985 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4617,7 +4617,7 @@ _lite_rule_alias = { "ns": "ns", } -_dont_uppercase = {"h", "bh", "cbh", "MS", "ms", "s", "me"} +_dont_uppercase = {"h", "bh", "cbh", "MS", "ms", "s", "me", "qe"} INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 0beea04f2f0ae..8cc3ace52a4d4 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -68,6 +68,8 @@ def test_construction(self): assert i1 == i2 assert i1 == i3 + # GH#54105 - Period can be confusingly instantiated with lowercase freq + # TODO: raise in the future an error when passing lowercase freq i4 = Period("2005", freq="M") assert i1 != i4 From e71aaf38bc90130e7932ae8d7206d3837f80772d Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 24 Oct 2023 11:43:31 +0200 Subject: [PATCH 14/15] add parameters Q, 2Q to test_read_json_table_orient_period_depr_freq --- pandas/tests/io/json/test_json_table_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 9519aa2887b92..507e99a4d6490 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -846,7 +846,7 @@ def test_read_json_orient_table_old_schema_version(self): result = pd.read_json(StringIO(df_json), orient="table") tm.assert_frame_equal(expected, result) - @pytest.mark.parametrize("freq", ["M", "2M"]) + @pytest.mark.parametrize("freq", ["M", "2M", "Q", "2Q"]) def test_read_json_table_orient_period_depr_freq(self, freq, recwarn): # GH#9586 df = DataFrame( From 261d9961f961a483b431afafbc7e6cc44348abba Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 24 Oct 2023 12:50:02 +0200 Subject: [PATCH 15/15] correct DatetimeProperties docs --- pandas/core/indexes/accessors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index f872b9eda4749..10a3fcc61b5bc 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -284,7 +284,7 @@ class DatetimeProperties(Properties): 2 2 dtype: int32 - >>> quarters_series = pd.Series(pd.date_range("2000-01-01", periods=3, freq="qe")) + >>> quarters_series = pd.Series(pd.date_range("2000-01-01", periods=3, freq="QE")) >>> quarters_series 0 2000-03-31 1 2000-06-30