From c7d82ecf4c3dfdb171ce2e2ecbbad10a6654edfc Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 5 Dec 2023 23:55:30 +0100 Subject: [PATCH 01/21] deprecate lowercase strings denoting freq for week, month, monthend, etc., fix tests --- pandas/_libs/tslibs/offsets.pyx | 74 ++++++++++------------ pandas/tests/resample/test_period_index.py | 4 +- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 47e507a0150e2..e33ac9974686c 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4548,35 +4548,9 @@ _lite_rule_alias = { "BYS": "BYS-JAN", # BYearBegin(month=1), "Min": "min", - "min": "min", - "ms": "ms", - "us": "us", - "ns": "ns", } -_dont_uppercase = { - "h", - "bh", - "cbh", - "MS", - "ms", - "s", - "me", - "qe", - "qe-dec", - "qe-jan", - "qe-feb", - "qe-mar", - "qe-apr", - "qe-may", - "qe-jun", - "qe-jul", - "qe-aug", - "qe-sep", - "qe-oct", - "qe-nov", - "ye", -} +_dont_uppercase = {"MS", "ms", "s"} INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" @@ -4595,7 +4569,8 @@ def _get_offset(name: str) -> BaseOffset: -------- _get_offset('EOM') --> BMonthEnd(1) """ - if name.lower() not in _dont_uppercase: + name_orig = name + if name not in _dont_uppercase: name = name.upper() name = _lite_rule_alias.get(name, name) name = _lite_rule_alias.get(name.lower(), name) @@ -4612,7 +4587,15 @@ def _get_offset(name: str) -> BaseOffset: except (ValueError, TypeError, KeyError) as err: # bad prefix or suffix raise ValueError(INVALID_FREQ_ERR_MSG.format( - f"{name}, failed to parse with error message: {repr(err)}") + f"{name_orig}, failed to parse with error message: {repr(err)}") + ) + if name != name_orig and name_orig != "d": + warnings.warn( + f"\'{name_orig}\' is deprecated and will be removed in a future " + f"version, please use \'{name_orig.upper()}\' " + f"instead.", + FutureWarning, + stacklevel=find_stack_level(), ) # cache _offset_map[name] = offset @@ -4688,39 +4671,46 @@ 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 in c_OFFSET_DEPR_FREQSTR: + if is_period is False and name.upper() in c_OFFSET_DEPR_FREQSTR: warnings.warn( f"\'{name}\' is deprecated, please use " - f"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' instead.", + f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", FutureWarning, stacklevel=find_stack_level(), ) - name = c_OFFSET_DEPR_FREQSTR[name] - if is_period is True and name in c_REVERSE_OFFSET_DEPR_FREQSTR: - if name.startswith("Y"): + name = c_OFFSET_DEPR_FREQSTR[name.upper()] + if is_period is True and name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR: + if name.upper().startswith("Y"): raise ValueError( - f"for Period, please use \'Y{name[2:]}\' " + f"for Period, please use \'Y{name.upper()[2:]}\' " f"instead of \'{name}\'" ) - if (name.startswith("B") or - name.startswith("S") or name.startswith("C")): + if (name.upper().startswith("B") or + name.upper().startswith("S") or name.upper().startswith("C")): raise ValueError(INVALID_FREQ_ERR_MSG.format(name)) else: raise ValueError( f"for Period, please use " - f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name)}\' " + f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name.upper())}\' " f"instead of \'{name}\'" ) - elif is_period is True and name in c_OFFSET_DEPR_FREQSTR: - if name.startswith("A"): + elif is_period is True and name.upper() in c_OFFSET_DEPR_FREQSTR: + if name.upper().startswith("A"): warnings.warn( f"\'{name}\' is deprecated and will be removed in a future " - f"version, please use \'{c_DEPR_ABBREVS.get(name)}\' " + f"version, please use \'{c_DEPR_ABBREVS.get(name.upper())}\' " f"instead.", FutureWarning, stacklevel=find_stack_level(), ) - name = c_OFFSET_DEPR_FREQSTR.get(name) + if name.upper() != name: + warnings.warn( + f"\'{name}\' is deprecated and will be removed in a future " + f"version, please use \'{name.upper()}\' instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = c_OFFSET_DEPR_FREQSTR.get(name.upper()) if sep != "" and not sep.isspace(): raise ValueError("separator must be spaces") diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 60b222179ba12..fb765194ed3ca 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -166,12 +166,12 @@ def test_basic_downsample(self, simple_period_range_series): ("Y-DEC", ""), ("Q-MAR", ""), ("M", ""), - ("w-thu", ""), + ("W-THU", ""), ], ) def test_not_subperiod(self, simple_period_range_series, rule, expected_error_msg): # These are incompatible period rules for resampling - ts = simple_period_range_series("1/1/1990", "6/30/1995", freq="w-wed") + ts = simple_period_range_series("1/1/1990", "6/30/1995", freq="W-WED") msg = ( "Frequency cannot be resampled to " f"{expected_error_msg}, as they are not sub or super periods" From 614710bdac5034531bc447ce9218051ce2e5c078 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 6 Dec 2023 00:37:31 +0100 Subject: [PATCH 02/21] fix tests --- pandas/_libs/tslibs/offsets.pyx | 16 ++++++++++------ pandas/tests/tseries/offsets/test_offsets.py | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e33ac9974686c..22c69c47d1ec5 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4548,9 +4548,13 @@ _lite_rule_alias = { "BYS": "BYS-JAN", # BYearBegin(month=1), "Min": "min", + "min": "min", + "ms": "ms", + "us": "us", + "ns": "ns", } -_dont_uppercase = {"MS", "ms", "s"} +_dont_uppercase = {"h", "bh", "cbh", "MS", "ms", "s"} INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" @@ -4592,8 +4596,7 @@ def _get_offset(name: str) -> BaseOffset: if name != name_orig and name_orig != "d": warnings.warn( f"\'{name_orig}\' is deprecated and will be removed in a future " - f"version, please use \'{name_orig.upper()}\' " - f"instead.", + f"version, please use \'{name_orig.upper()}\' instead.", FutureWarning, stacklevel=find_stack_level(), ) @@ -4686,7 +4689,8 @@ cpdef to_offset(freq, bint is_period=False): f"instead of \'{name}\'" ) if (name.upper().startswith("B") or - name.upper().startswith("S") or name.upper().startswith("C")): + name.upper().startswith("S") or + name.upper().startswith("C")): raise ValueError(INVALID_FREQ_ERR_MSG.format(name)) else: raise ValueError( @@ -4698,8 +4702,8 @@ cpdef to_offset(freq, bint is_period=False): if name.upper().startswith("A"): warnings.warn( f"\'{name}\' is deprecated and will be removed in a future " - f"version, please use \'{c_DEPR_ABBREVS.get(name.upper())}\' " - f"instead.", + f"version, please use " + f"\'{c_DEPR_ABBREVS.get(name.upper())}\' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index ddf56e68b1611..4fc97bc3969df 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -784,8 +784,8 @@ def test_get_offset(): pairs = [ ("B", BDay()), ("b", BDay()), - ("bme", BMonthEnd()), - ("Bme", BMonthEnd()), + ("BME", BMonthEnd()), + ("BME", BMonthEnd()), ("W-MON", Week(weekday=0)), ("W-TUE", Week(weekday=1)), ("W-WED", Week(weekday=2)), From 458a9c17c11a1d9fd3b646435870419d4a5ccccf Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 6 Dec 2023 16:11:44 +0100 Subject: [PATCH 03/21] fix tests --- pandas/_libs/tslibs/offsets.pyx | 37 +++++++++++-------- .../indexes/datetimes/test_partial_slicing.py | 2 +- pandas/tests/scalar/period/test_period.py | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 22c69c47d1ec5..07e2feceec26a 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4675,13 +4675,16 @@ 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.upper() in c_OFFSET_DEPR_FREQSTR: - warnings.warn( - f"\'{name}\' is deprecated, please use " - f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - name = c_OFFSET_DEPR_FREQSTR[name.upper()] + if name == "m" and (n > 0 or stride == "-"): + name = name + else: + warnings.warn( + f"\'{name}\' is deprecated, please use " + f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = c_OFFSET_DEPR_FREQSTR[name.upper()] if is_period is True and name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR: if name.upper().startswith("Y"): raise ValueError( @@ -4707,14 +4710,18 @@ cpdef to_offset(freq, bint is_period=False): FutureWarning, stacklevel=find_stack_level(), ) - if name.upper() != name: - warnings.warn( - f"\'{name}\' is deprecated and will be removed in a future " - f"version, please use \'{name.upper()}\' instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - name = c_OFFSET_DEPR_FREQSTR.get(name.upper()) + if name == "m" and (n > 0 or stride == "-"): + name = name + else: + if name.upper() != name: + warnings.warn( + f"\'{name}\' is deprecated and will be removed in " + f"a future version, please use \'{name.upper()}\' " + f"instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = c_OFFSET_DEPR_FREQSTR.get(name.upper()) if sep != "" and not sep.isspace(): raise ValueError("separator must be spaces") diff --git a/pandas/tests/indexes/datetimes/test_partial_slicing.py b/pandas/tests/indexes/datetimes/test_partial_slicing.py index 0ebb88afb6c86..8b493fc61cb58 100644 --- a/pandas/tests/indexes/datetimes/test_partial_slicing.py +++ b/pandas/tests/indexes/datetimes/test_partial_slicing.py @@ -236,7 +236,7 @@ def test_partial_slice_second_precision(self): rng = date_range( start=datetime(2005, 1, 1, 0, 0, 59, microsecond=999990), periods=20, - freq="US", + freq="us", ) s = Series(np.arange(20), rng) diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 3e91264fdb3b1..f656e5f331cc6 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -82,7 +82,7 @@ def test_construction(self): assert i1 == i3 i1 = Period("1982", freq="min") - i2 = Period("1982", freq="MIN") + i2 = Period("1982", freq="Min") assert i1 == i2 i1 = Period(year=2005, month=3, day=1, freq="D") From e9c8af5af5e9aced89df1fe66aa6e88b5876a3dc Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 7 Dec 2023 16:47:42 +0100 Subject: [PATCH 04/21] correct def _get_offset, fix tests --- pandas/_libs/tslibs/offsets.pyx | 85 +++++++++---------- .../tests/indexes/period/test_constructors.py | 6 +- pandas/tests/resample/test_base.py | 2 +- pandas/tests/resample/test_datetime_index.py | 14 +-- pandas/tests/tslibs/test_to_offset.py | 2 +- pandas/tests/window/test_groupby.py | 4 +- 6 files changed, 56 insertions(+), 57 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 07e2feceec26a..33319367c6578 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4573,7 +4573,28 @@ def _get_offset(name: str) -> BaseOffset: -------- _get_offset('EOM') --> BMonthEnd(1) """ - name_orig = name + if ( + name not in _lite_rule_alias + and (name.upper() in _lite_rule_alias) + and name != "ms" + ): + warnings.warn( + f"\'{name}\' is deprecated and will be removed in a future " + f"version, please use \'{name.upper()}\' instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + elif ( + name not in _lite_rule_alias + and (name.lower() in _lite_rule_alias) + and name != "MS" + ): + warnings.warn( + f"\'{name}\' is deprecated and will be removed in a future " + f"version, please use \'{name.lower()}\' instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) if name not in _dont_uppercase: name = name.upper() name = _lite_rule_alias.get(name, name) @@ -4591,14 +4612,7 @@ def _get_offset(name: str) -> BaseOffset: except (ValueError, TypeError, KeyError) as err: # bad prefix or suffix raise ValueError(INVALID_FREQ_ERR_MSG.format( - f"{name_orig}, failed to parse with error message: {repr(err)}") - ) - if name != name_orig and name_orig != "d": - warnings.warn( - f"\'{name_orig}\' is deprecated and will be removed in a future " - f"version, please use \'{name_orig.upper()}\' instead.", - FutureWarning, - stacklevel=find_stack_level(), + f"{name}, failed to parse with error message: {repr(err)}") ) # cache _offset_map[name] = offset @@ -4674,54 +4688,39 @@ 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.upper() in c_OFFSET_DEPR_FREQSTR: - if name == "m" and (n > 0 or stride == "-"): - name = name - else: - warnings.warn( - f"\'{name}\' is deprecated, please use " - f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - name = c_OFFSET_DEPR_FREQSTR[name.upper()] - if is_period is True and name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR: - if name.upper().startswith("Y"): + if is_period is False and name in c_OFFSET_DEPR_FREQSTR: + warnings.warn( + f"\'{name}\' is deprecated, please use " + f"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = c_OFFSET_DEPR_FREQSTR[name.upper()] + if is_period is True and name in c_REVERSE_OFFSET_DEPR_FREQSTR: + if name.startswith("Y"): raise ValueError( - f"for Period, please use \'Y{name.upper()[2:]}\' " + f"for Period, please use \'Y{name[2:]}\' " f"instead of \'{name}\'" ) - if (name.upper().startswith("B") or - name.upper().startswith("S") or - name.upper().startswith("C")): + if (name.startswith("B") or + name.startswith("S") or name.startswith("C")): raise ValueError(INVALID_FREQ_ERR_MSG.format(name)) else: raise ValueError( f"for Period, please use " - f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name.upper())}\' " + f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name)}\' " f"instead of \'{name}\'" ) - elif is_period is True and name.upper() in c_OFFSET_DEPR_FREQSTR: - if name.upper().startswith("A"): + elif is_period is True and name in c_OFFSET_DEPR_FREQSTR: + if name.startswith("A"): warnings.warn( f"\'{name}\' is deprecated and will be removed in a future " - f"version, please use " - f"\'{c_DEPR_ABBREVS.get(name.upper())}\' instead.", + f"version, please use \'{c_DEPR_ABBREVS.get(name)}\' " + f"instead.", FutureWarning, stacklevel=find_stack_level(), ) - if name == "m" and (n > 0 or stride == "-"): - name = name - else: - if name.upper() != name: - warnings.warn( - f"\'{name}\' is deprecated and will be removed in " - f"a future version, please use \'{name.upper()}\' " - f"instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - name = c_OFFSET_DEPR_FREQSTR.get(name.upper()) + name = c_OFFSET_DEPR_FREQSTR.get(name) if sep != "" and not sep.isspace(): raise ValueError("separator must be spaces") diff --git a/pandas/tests/indexes/period/test_constructors.py b/pandas/tests/indexes/period/test_constructors.py index aecd3b3bace9a..4c347081e3521 100644 --- a/pandas/tests/indexes/period/test_constructors.py +++ b/pandas/tests/indexes/period/test_constructors.py @@ -533,7 +533,7 @@ def test_constructor(self): assert i1.freq == end_intv.freq assert i1[-1] == end_intv - end_intv = Period("2006-12-31", "1w") + end_intv = Period("2006-12-31", "1W") i2 = period_range(end=end_intv, periods=10) assert len(i1) == len(i2) assert (i1 == i2).all() @@ -554,7 +554,7 @@ def test_constructor(self): assert i2[0] == end_intv # Mixed freq should fail - vals = [end_intv, Period("2006-12-31", "w")] + vals = [end_intv, Period("2006-12-31", "W")] msg = r"Input has different freq=W-SUN from PeriodIndex\(freq=B\)" with pytest.raises(IncompatibleFrequency, match=msg): PeriodIndex(vals) @@ -564,7 +564,7 @@ def test_constructor(self): # tuple freq disallowed GH#34703 with pytest.raises(TypeError, match="pass as a string instead"): - Period("2006-12-31", ("w", 1)) + Period("2006-12-31", ("W", 1)) @pytest.mark.parametrize( "freq", ["M", "Q", "Y", "D", "B", "min", "s", "ms", "us", "ns", "h"] diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index 7176cdf6ff9e4..cba98c98b125b 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -303,7 +303,7 @@ def test_resample_empty_dtypes(index, dtype, resample_method): # with Cython bounds-checking disabled) or an IndexError. We just run # them to ensure they no longer do. (GH #10228) empty_series_dti = Series([], index, dtype) - rs = empty_series_dti.resample("d", group_keys=False) + rs = empty_series_dti.resample("D", group_keys=False) try: getattr(rs, resample_method)() except DataError: diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 8a725c6e51e3f..20540344fd2dc 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -258,7 +258,7 @@ def _ohlc(group): def test_resample_how_callables(unit): # GH#7929 data = np.arange(5, dtype=np.int64) - ind = date_range(start="2014-01-01", periods=len(data), freq="d").as_unit(unit) + ind = date_range(start="2014-01-01", periods=len(data), freq="D").as_unit(unit) df = DataFrame({"A": data, "B": data}, index=ind) def fn(x, a=1): @@ -353,7 +353,7 @@ def test_resample_basic_from_daily(unit): s = Series(np.random.default_rng(2).random(len(dti)), dti) # to weekly - result = s.resample("w-sun").last() + result = s.resample("W-SUN").last() assert len(result) == 3 assert (result.index.dayofweek == [6, 6, 6]).all() @@ -1265,7 +1265,7 @@ def test_anchored_lowercase_buglet(unit): dates = date_range("4/16/2012 20:00", periods=50000, freq="s").as_unit(unit) ts = Series(np.random.default_rng(2).standard_normal(len(dates)), index=dates) # it works! - ts.resample("d").mean() + ts.resample("D").mean() def test_upsample_apply_functions(unit): @@ -1605,9 +1605,9 @@ def test_groupby_with_dst_time_change(unit): ) df = DataFrame([1, 2], index=index) - result = df.groupby(Grouper(freq="1d")).last() + result = df.groupby(Grouper(freq="1D")).last() expected_index_values = date_range( - "2016-11-02", "2016-11-24", freq="d", tz="America/Chicago" + "2016-11-02", "2016-11-24", freq="D", tz="America/Chicago" ).as_unit(unit) index = DatetimeIndex(expected_index_values) @@ -2102,7 +2102,7 @@ def test_resample_M_Q_Y_A_deprecated(freq, freq_depr): # GH#9586 depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." - s = Series(range(10), index=date_range("20130101", freq="d", periods=10)) + s = Series(range(10), index=date_range("20130101", freq="D", periods=10)) expected = s.resample(freq).mean() with tm.assert_produces_warning(FutureWarning, match=depr_msg): result = s.resample(freq_depr).mean() @@ -2121,7 +2121,7 @@ def test_resample_BM_BQ_deprecated(freq, freq_depr): # GH#52064 depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." - s = Series(range(10), index=date_range("20130101", freq="d", periods=10)) + s = Series(range(10), index=date_range("20130101", freq="D", periods=10)) expected = s.resample(freq).mean() with tm.assert_produces_warning(FutureWarning, match=depr_msg): result = s.resample(freq_depr).mean() diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index ef68408305232..eac100486c6d2 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -126,7 +126,7 @@ def test_to_offset_leading_zero(freqstr, expected): assert result.n == expected -@pytest.mark.parametrize("freqstr,expected", [("+1d", 1), ("+2h30min", 150)]) +@pytest.mark.parametrize("freqstr,expected", [("+1D", 1), ("+2h30min", 150)]) def test_to_offset_leading_plus(freqstr, expected): result = to_offset(freqstr) assert result.n == expected diff --git a/pandas/tests/window/test_groupby.py b/pandas/tests/window/test_groupby.py index 400bf10817ab8..fc1fd3a3da03d 100644 --- a/pandas/tests/window/test_groupby.py +++ b/pandas/tests/window/test_groupby.py @@ -582,7 +582,7 @@ def test_groupby_rolling_string_index(self): groups = df.groupby("group") df["count_to_date"] = groups.cumcount() - rolling_groups = groups.rolling("10d", on="eventTime") + rolling_groups = groups.rolling("10D", on="eventTime") result = rolling_groups.apply(lambda df: df.shape[0]) expected = DataFrame( [ @@ -625,7 +625,7 @@ def test_groupby_rolling_count_closed_on(self, unit): ) result = ( df.groupby("group") - .rolling("3d", on="date", closed="left")["column1"] + .rolling("3D", on="date", closed="left")["column1"] .count() ) dti = DatetimeIndex( From 73f68f07fedede3e0e15c425031b2a644fe45678 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Fri, 8 Dec 2023 00:35:27 +0100 Subject: [PATCH 05/21] add tests, fix tests --- pandas/_libs/tslibs/dtypes.pyx | 2 + pandas/_libs/tslibs/offsets.pyx | 54 +++++++++++++------ pandas/tests/arrays/test_datetimes.py | 37 +++++++++++++ pandas/tests/indexes/period/test_period.py | 40 +++++++++++++- .../timedeltas/test_timedelta_range.py | 16 ++++++ pandas/tests/resample/test_period_index.py | 31 ++++++++++- pandas/tests/scalar/period/test_period.py | 24 +++++++++ 7 files changed, 184 insertions(+), 20 deletions(-) diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx index 17f517e5e7264..0d5c264f262d8 100644 --- a/pandas/_libs/tslibs/dtypes.pyx +++ b/pandas/_libs/tslibs/dtypes.pyx @@ -407,8 +407,10 @@ cdef dict c_DEPR_ABBREVS = { "L": "ms", "l": "ms", "U": "us", + "US": "us", "u": "us", "N": "ns", + "NS": "ns", "n": "ns", } diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 33319367c6578..1a776c957e6e0 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4579,8 +4579,7 @@ def _get_offset(name: str) -> BaseOffset: and name != "ms" ): warnings.warn( - f"\'{name}\' is deprecated and will be removed in a future " - f"version, please use \'{name.upper()}\' instead.", + f"\'{name}\' is deprecated, please use \'{name.upper()}\' instead.", FutureWarning, stacklevel=find_stack_level(), ) @@ -4590,8 +4589,7 @@ def _get_offset(name: str) -> BaseOffset: and name != "MS" ): warnings.warn( - f"\'{name}\' is deprecated and will be removed in a future " - f"version, please use \'{name.lower()}\' instead.", + f"\'{name}\' is deprecated, please use \'{name.lower()}\' instead.", FutureWarning, stacklevel=find_stack_level(), ) @@ -4688,39 +4686,61 @@ 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 in c_OFFSET_DEPR_FREQSTR: + if is_period is False and name.upper() in c_OFFSET_DEPR_FREQSTR: + if name == "m" and (n > 0 or stride == "-"): + name = name + else: + warnings.warn( + f"\'{name}\' is deprecated, please use " + f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = c_OFFSET_DEPR_FREQSTR[name.upper()] + elif (is_period is False and + name != name.upper() and + name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR): warnings.warn( f"\'{name}\' is deprecated, please use " - f"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' instead.", + f"\'{name.upper()}\' instead.", FutureWarning, stacklevel=find_stack_level(), ) - name = c_OFFSET_DEPR_FREQSTR[name.upper()] - if is_period is True and name in c_REVERSE_OFFSET_DEPR_FREQSTR: - if name.startswith("Y"): + name = name.upper() + if is_period is True and name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR: + if name.upper().startswith("Y"): raise ValueError( - f"for Period, please use \'Y{name[2:]}\' " + f"for Period, please use \'Y{name.upper()[2:]}\' " f"instead of \'{name}\'" ) - if (name.startswith("B") or - name.startswith("S") or name.startswith("C")): + if (name.upper().startswith("B") or + name.upper().startswith("S") or + name.upper().startswith("C")): raise ValueError(INVALID_FREQ_ERR_MSG.format(name)) else: raise ValueError( f"for Period, please use " - f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name)}\' " + f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name.upper())}\' " f"instead of \'{name}\'" ) - elif is_period is True and name in c_OFFSET_DEPR_FREQSTR: - if name.startswith("A"): + elif is_period is True and name.upper() in c_OFFSET_DEPR_FREQSTR: + if name.upper().startswith("A"): warnings.warn( f"\'{name}\' is deprecated and will be removed in a future " - f"version, please use \'{c_DEPR_ABBREVS.get(name)}\' " + f"version, please use " + f"\'{c_DEPR_ABBREVS.get(name.upper())}\' instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + if name.upper() != name: + warnings.warn( + f"\'{name}\' is deprecated and will be removed in " + f"a future version, please use \'{name.upper()}\' " f"instead.", FutureWarning, stacklevel=find_stack_level(), ) - name = c_OFFSET_DEPR_FREQSTR.get(name) + name = c_OFFSET_DEPR_FREQSTR.get(name.upper()) 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 1fa55f13af2a8..e440cf75d92b4 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -779,6 +779,43 @@ def test_date_range_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr): result = pd.date_range("1/1/2000", periods=4, freq=freq_depr) tm.assert_index_equal(result, expected) + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2h", "2H"), + ("2s", "2S"), + ], + ) + def test_date_range_uppercase_frequency_deprecated(self, freq, freq_depr): + # GH#9586, GH#54939 + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " + f"future version. Please use '{freq[1:]}' instead." + + expected = pd.date_range("1/1/2000", periods=4, freq=freq) + with tm.assert_produces_warning(FutureWarning, match=depr_msg): + result = pd.date_range("1/1/2000", periods=4, freq=freq_depr) + tm.assert_index_equal(result, expected) + + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2ME", "2me"), + ("2ME", "2m"), + ("2QE-SEP", "2q-sep"), + ("2W", "2w"), + ("2min", "2MIN"), + ("2us", "2US"), + ], + ) + def test_date_range_lowercase_frequency_deprecated(self, freq, freq_depr): + # GH#9586, GH#54939 + depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + + expected = pd.date_range("1/1/2000", periods=4, freq=freq) + with tm.assert_produces_warning(FutureWarning, match=depr_msg): + result = pd.date_range("1/1/2000", periods=4, freq=freq_depr) + tm.assert_index_equal(result, expected) + def test_factorize_sort_without_freq(): dta = DatetimeArray._from_sequence([0, 2, 1]) diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 1354f33291c45..1233f051dce02 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -90,7 +90,7 @@ def test_period_index_length(self): assert i1.freq == end_intv.freq assert i1[-1] == end_intv - end_intv = Period("2006-12-31", "1w") + end_intv = Period("2006-12-31", "1W") i2 = period_range(end=end_intv, periods=10) assert len(i1) == len(i2) assert (i1 == i2).all() @@ -126,7 +126,7 @@ def test_period_index_length(self): assert i2[0] == end_intv # Mixed freq should fail - vals = [end_intv, Period("2006-12-31", "w")] + vals = [end_intv, Period("2006-12-31", "W")] msg = r"Input has different freq=W-SUN from PeriodIndex\(freq=B\)" with pytest.raises(IncompatibleFrequency, match=msg): PeriodIndex(vals) @@ -325,6 +325,42 @@ def test_period_index_frequency_invalid_freq(self, freq_depr): with pytest.raises(ValueError, match=msg): period_range("2020-01", "2020-05", freq=freq_depr) + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2M", "2m"), + ("2Q-SEP", "2q-sep"), + ("2Y", "2y"), + ("2Y-FEB", "2a-feb"), + ("2s", "2S"), + ], + ) + def test_lowercase_freq_deprecated_from_time_series(self, freq, freq_depr): + # GH#9586, GH#54939 + msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " + f"future version. Please use '{freq[1:]}' instead." + + with tm.assert_produces_warning(FutureWarning, match=msg): + index = period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009") + series = Series(1, index=index) + assert isinstance(series, Series) + + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2W", "2w"), + ("2min", "2MIN"), + ], + ) + def test_uppercase_freq_deprecated_from_time_series(self, freq, freq_depr): + # GH#9586, GH#54939 + msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." + + with tm.assert_produces_warning(FutureWarning, match=msg): + index = period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009") + series = Series(1, index=index) + assert isinstance(series, Series) + def test_maybe_convert_timedelta(): pi = PeriodIndex(["2000", "2001"], freq="D") diff --git a/pandas/tests/indexes/timedeltas/test_timedelta_range.py b/pandas/tests/indexes/timedeltas/test_timedelta_range.py index f22bdb7a90516..62dc30dedde29 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta_range.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta_range.py @@ -88,6 +88,22 @@ def test_timedelta_range_H_T_deprecated(self, freq, msg_freq): expected = timedelta_range(start="0 days", end="4 days", freq=freq) tm.assert_index_equal(result, expected) + @pytest.mark.parametrize( + "freq_depr, freq", + [ + ("S", "s"), + ("H", "h"), + ("US", "us"), + ("NS", "ns"), + ], + ) + def test_timedelta_range_uppercase_freq_deprecated(self, freq, freq_depr): + # GH#56346 + expected = to_timedelta(np.arange(5), unit=freq) + with tm.assert_produces_warning(FutureWarning, match=freq_depr): + result = to_timedelta(np.arange(5), unit=freq_depr) + tm.assert_index_equal(result, expected) + def test_errors(self): # not enough params msg = ( diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index fb765194ed3ca..d36cc1655c014 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -970,6 +970,33 @@ def test_resample_t_l_deprecated(self): result = ser.resample("T").mean() tm.assert_series_equal(result, expected) + @pytest.mark.parametrize( + "freq, freq_depr, freq_res, freq_depr_res, data", + [ + ("2Q", "2q", "2Y", "2y", [0.5]), + ("2M", "2m", "2Q", "2q", [1.0, 3.0]), + ], + ) + def test_resample_lowercase_frequency_deprecated( + self, freq, freq_depr, freq_res, freq_depr_res, data + ): + # GH#56346 + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " + f"future version. Please use '{freq[1:]}' instead." + depr_msg_res = f"'{freq_depr_res[1:]}' is deprecated and will be removed in a " + f"future version. Please use '{freq_res[1:]}' instead." + + with tm.assert_produces_warning(FutureWarning, match=depr_msg): + rng_l = period_range("2020-01-01", "2020-08-01", freq=freq_depr) + ser = Series(np.arange(len(rng_l)), index=rng_l) + + rng = period_range("2020-01-01", "2020-08-01", freq=freq_res) + expected = Series(data=data, index=rng) + + with tm.assert_produces_warning(FutureWarning, match=depr_msg_res): + result = ser.resample(freq_depr_res).mean() + tm.assert_series_equal(result, expected) + @pytest.mark.parametrize( "freq,freq_depr", @@ -979,10 +1006,12 @@ def test_resample_t_l_deprecated(self): ("2Q-FEB", "2QE-FEB"), ("2Y", "2YE"), ("2Y-MAR", "2YE-MAR"), + ("2M", "2me"), + ("2Y-MAR", "2ye-mar"), ], ) def test_resample_frequency_ME_QE_YE_error_message(series_and_frame, freq, freq_depr): - # GH#9586 + # GH#9586, GH#56346 msg = f"for Period, please use '{freq[1:]}' instead of '{freq_depr[1:]}'" obj = series_and_frame diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index f656e5f331cc6..390b0216d1832 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -1073,6 +1073,30 @@ def test_properties_secondly(self): == 29 ) + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2M", "2m"), + ("2Q", "2m"), + ("2Y-SEP", "2q-sep"), + ("2h", "2H"), + ("2s", "2S"), + ("2us", "2US"), + ("2us", "2US"), + ("2ns", "2NS"), + ], + ) + def test_period_upperlowercase_frequency_deprecated(self, freq, freq_depr): + # GH#56346 + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " + f"future version. Please use '{freq[1:]}' instead." + + with tm.assert_produces_warning(FutureWarning, match=depr_msg): + Period("2016-03-01 09:00", freq=freq_depr) + + p1 = Period("2016-03-01 09:00", freq=freq) + assert isinstance(p1, Period) + class TestPeriodField: def test_get_period_field_array_raises_on_out_of_range(self): From eea9b69aa3f0a438b4aefef08cfd4c66d2cc4c37 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Mon, 11 Dec 2023 02:02:04 +0100 Subject: [PATCH 06/21] fix tests --- pandas/tests/arrays/test_datetimes.py | 1 - pandas/tests/scalar/timedelta/test_timedelta.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index e440cf75d92b4..154d71de5b4bc 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -804,7 +804,6 @@ def test_date_range_uppercase_frequency_deprecated(self, freq, freq_depr): ("2QE-SEP", "2q-sep"), ("2W", "2w"), ("2min", "2MIN"), - ("2us", "2US"), ], ) def test_date_range_lowercase_frequency_deprecated(self, freq, freq_depr): diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index ac605df935226..e676dd4780bd0 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -461,7 +461,7 @@ def conv(v): assert Timedelta("1000") == np.timedelta64(1000, "ns") assert Timedelta("1000ns") == np.timedelta64(1000, "ns") - assert Timedelta("1000NS") == np.timedelta64(1000, "ns") + assert Timedelta("1000Ns") == np.timedelta64(1000, "ns") assert Timedelta("10us") == np.timedelta64(10000, "ns") assert Timedelta("100us") == np.timedelta64(100000, "ns") From 386eb57c960235a625d1a5fa52f401f82963f756 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Mon, 11 Dec 2023 23:26:03 +0100 Subject: [PATCH 07/21] correct parse_timedelta_unit, to_offset, fix tests, add tests --- pandas/_libs/tslibs/dtypes.pyx | 2 +- pandas/_libs/tslibs/offsets.pyx | 2 +- pandas/_libs/tslibs/timedeltas.pyx | 6 ++--- .../tests/scalar/timedelta/test_timedelta.py | 22 ++++++++++++++++--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx index 0d5c264f262d8..6c5ac75b0cb90 100644 --- a/pandas/_libs/tslibs/dtypes.pyx +++ b/pandas/_libs/tslibs/dtypes.pyx @@ -511,7 +511,7 @@ class Resolution(Enum): warnings.warn( f"\'{freq}\' is deprecated and will be removed in a future " f"version. Please use \'{abbrev}\' " - "instead of \'{freq}\'.", + f"instead of \'{freq}\'.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 1a776c957e6e0..404e8d1fe7203 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4687,7 +4687,7 @@ 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.upper() in c_OFFSET_DEPR_FREQSTR: - if name == "m" and (n > 0 or stride == "-"): + if n > 0 or stride == "-": name = name else: warnings.warn( diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 5852a7d95d994..4da7d2ddb89fd 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -719,15 +719,15 @@ cpdef inline str parse_timedelta_unit(str unit): return "ns" elif unit == "M": return unit - elif unit in c_DEPR_ABBREVS: + elif unit.upper() in c_DEPR_ABBREVS and unit != c_DEPR_ABBREVS.get(unit.upper()): warnings.warn( f"\'{unit}\' is deprecated and will be removed in a " - f"future version. Please use \'{c_DEPR_ABBREVS.get(unit)}\' " + f"future version. Please use \'{c_DEPR_ABBREVS.get(unit.upper())}\' " f"instead of \'{unit}\'.", FutureWarning, stacklevel=find_stack_level(), ) - unit = c_DEPR_ABBREVS[unit] + unit = c_DEPR_ABBREVS[unit.upper()] try: return timedelta_abbrevs[unit.lower()] except KeyError: diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index e676dd4780bd0..e3cc63230cd16 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -461,13 +461,10 @@ def conv(v): assert Timedelta("1000") == np.timedelta64(1000, "ns") assert Timedelta("1000ns") == np.timedelta64(1000, "ns") - assert Timedelta("1000Ns") == np.timedelta64(1000, "ns") assert Timedelta("10us") == np.timedelta64(10000, "ns") assert Timedelta("100us") == np.timedelta64(100000, "ns") assert Timedelta("1000us") == np.timedelta64(1000000, "ns") - assert Timedelta("1000Us") == np.timedelta64(1000000, "ns") - assert Timedelta("1000uS") == np.timedelta64(1000000, "ns") assert Timedelta("1ms") == np.timedelta64(1000000, "ns") assert Timedelta("10ms") == np.timedelta64(10000000, "ns") @@ -634,6 +631,25 @@ def test_resolution_deprecated(self): result = Timedelta.resolution assert result == Timedelta(nanoseconds=1) + @pytest.mark.parametrize( + "unit, unit_depr", + [ + ("2h", "2H"), + ("2us", "2Us"), + ("2us", "2US"), + ("2ns", "2nS"), + ("2ns", "2Ns"), + ], + ) + def test_timedelta_uppercase_units_deprecated(self, unit, unit_depr): + # GH#56346 + depr_msg = f"'{unit_depr[1:]}' is deprecated and will be removed in a " + f"future version. Please use '{unit[1:]}' instead." + + with tm.assert_produces_warning(FutureWarning, match=depr_msg): + result = Timedelta(unit_depr) + assert result == Timedelta(unit) + @pytest.mark.parametrize( "value, expected", From 25bfbef7b70164dd107c0ac96de8d675a39004c1 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 12 Dec 2023 16:02:44 +0100 Subject: [PATCH 08/21] fix tests --- pandas/tests/indexes/period/test_period_range.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pandas/tests/indexes/period/test_period_range.py b/pandas/tests/indexes/period/test_period_range.py index b6b32613c8d95..ad972efbc7a94 100644 --- a/pandas/tests/indexes/period/test_period_range.py +++ b/pandas/tests/indexes/period/test_period_range.py @@ -251,11 +251,7 @@ def test_uppercase_us_ns_deprecated_from_time_series(self, freq, freq_depr): f"future version. Please use '{freq[1:]}' instead." with tm.assert_produces_warning(FutureWarning, match=msg): - period_range( - freq=freq_depr, - start="2020-01-01 00:00:00 00:00:00", - end="2020-01-01 00:00:00 00:00:01", - ) + period_range("2020-01-01 00:00:00 00:00", periods=2, freq=freq_depr) @pytest.mark.parametrize( "freq, freq_depr", @@ -269,11 +265,7 @@ def test_mixcase_us_ns_deprecated_from_time_series(self, freq, freq_depr): msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead." with tm.assert_produces_warning(FutureWarning, match=msg): - period_range( - freq=freq_depr, - start="2020-01-01 00:00:00 00:00:00", - end="2020-01-01 00:00:00 00:00:01", - ) + period_range("2020-01-01 00:00:00 00:00", periods=2, freq=freq_depr) @pytest.mark.parametrize( "freq, freq_depr", From 435db7686c4f92d281a363712162114216c5303a Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Fri, 15 Dec 2023 18:33:58 +0100 Subject: [PATCH 09/21] deprecate 'Min' in favour of 'min' --- pandas/_libs/tslibs/offsets.pyx | 3 +- pandas/tests/frame/methods/test_at_time.py | 2 +- .../indexes/datetimes/methods/test_repeat.py | 2 +- .../indexes/datetimes/methods/test_round.py | 4 +- .../indexes/period/methods/test_asfreq.py | 14 +- .../tests/indexes/period/test_constructors.py | 2 +- pandas/tests/indexes/period/test_period.py | 2 +- .../indexes/timedeltas/test_scalar_compat.py | 2 +- pandas/tests/plotting/test_datetimelike.py | 12 +- pandas/tests/resample/test_datetime_index.py | 26 +-- pandas/tests/resample/test_resample_api.py | 2 +- .../tests/resample/test_resampler_grouper.py | 2 +- pandas/tests/scalar/period/test_asfreq.py | 180 ++++++++++-------- pandas/tests/scalar/period/test_period.py | 14 +- .../scalar/timestamp/methods/test_round.py | 2 +- pandas/tests/tseries/offsets/test_offsets.py | 4 +- 16 files changed, 146 insertions(+), 127 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 966782268000b..dca5123d911b1 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1755,7 +1755,7 @@ cdef class BusinessDay(BusinessMixin): s -= hrs * 3600 mts = int(s / 60) if mts != 0: - off_str += str(mts) + "Min" + off_str += str(mts) + "min" s -= mts * 60 if s != 0: off_str += str(s) + "s" @@ -4643,7 +4643,6 @@ _lite_rule_alias = { "BYE": "BYE-DEC", # BYearEnd(month=12), "BYS": "BYS-JAN", # BYearBegin(month=1), - "Min": "min", "min": "min", "ms": "ms", "us": "us", diff --git a/pandas/tests/frame/methods/test_at_time.py b/pandas/tests/frame/methods/test_at_time.py index 4c1434bd66aff..313cce50452d5 100644 --- a/pandas/tests/frame/methods/test_at_time.py +++ b/pandas/tests/frame/methods/test_at_time.py @@ -58,7 +58,7 @@ def test_at_time_midnight(self, frame_or_series): def test_at_time_nonexistent(self, frame_or_series): # time doesn't exist - rng = date_range("1/1/2012", freq="23Min", periods=384) + rng = date_range("1/1/2012", freq="23min", periods=384) ts = DataFrame(np.random.default_rng(2).standard_normal(len(rng)), rng) ts = tm.get_obj(ts, frame_or_series) rs = ts.at_time("16:00") diff --git a/pandas/tests/indexes/datetimes/methods/test_repeat.py b/pandas/tests/indexes/datetimes/methods/test_repeat.py index 92501755f8c5b..32e4fb041ba29 100644 --- a/pandas/tests/indexes/datetimes/methods/test_repeat.py +++ b/pandas/tests/indexes/datetimes/methods/test_repeat.py @@ -63,7 +63,7 @@ def test_repeat(self, tz_naive_fixture, unit): reps = 2 msg = "the 'axis' parameter is not supported" - rng = date_range(start="2016-01-01", periods=2, freq="30Min", tz=tz, unit=unit) + rng = date_range(start="2016-01-01", periods=2, freq="30min", tz=tz, unit=unit) expected_rng = DatetimeIndex( [ diff --git a/pandas/tests/indexes/datetimes/methods/test_round.py b/pandas/tests/indexes/datetimes/methods/test_round.py index cde4a3a65804d..4a53d4e8d0513 100644 --- a/pandas/tests/indexes/datetimes/methods/test_round.py +++ b/pandas/tests/indexes/datetimes/methods/test_round.py @@ -42,7 +42,7 @@ def test_round_invalid(self, freq, error_msg): def test_round(self, tz_naive_fixture, unit): tz = tz_naive_fixture - rng = date_range(start="2016-01-01", periods=5, freq="30Min", tz=tz, unit=unit) + rng = date_range(start="2016-01-01", periods=5, freq="30min", tz=tz, unit=unit) elt = rng[1] expected_rng = DatetimeIndex( @@ -104,7 +104,7 @@ def test_round4(self, tz_naive_fixture): def test_no_rounding_occurs(self, tz_naive_fixture): # GH 21262 tz = tz_naive_fixture - rng = date_range(start="2016-01-01", periods=5, freq="2Min", tz=tz) + rng = date_range(start="2016-01-01", periods=5, freq="2min", tz=tz) expected_rng = DatetimeIndex( [ diff --git a/pandas/tests/indexes/period/methods/test_asfreq.py b/pandas/tests/indexes/period/methods/test_asfreq.py index ed078a3e8fb8b..b322833d9b610 100644 --- a/pandas/tests/indexes/period/methods/test_asfreq.py +++ b/pandas/tests/indexes/period/methods/test_asfreq.py @@ -15,7 +15,7 @@ def test_asfreq(self): pi3 = period_range(freq="M", start="1/1/2001", end="1/1/2001") pi4 = period_range(freq="D", start="1/1/2001", end="1/1/2001") pi5 = period_range(freq="h", start="1/1/2001", end="1/1/2001 00:00") - pi6 = period_range(freq="Min", start="1/1/2001", end="1/1/2001 00:00") + pi6 = period_range(freq="min", start="1/1/2001", end="1/1/2001 00:00") pi7 = period_range(freq="s", start="1/1/2001", end="1/1/2001 00:00:00") assert pi1.asfreq("Q", "s") == pi2 @@ -23,35 +23,35 @@ def test_asfreq(self): assert pi1.asfreq("M", "start") == pi3 assert pi1.asfreq("D", "StarT") == pi4 assert pi1.asfreq("h", "beGIN") == pi5 - assert pi1.asfreq("Min", "s") == pi6 + assert pi1.asfreq("min", "s") == pi6 assert pi1.asfreq("s", "s") == pi7 assert pi2.asfreq("Y", "s") == pi1 assert pi2.asfreq("M", "s") == pi3 assert pi2.asfreq("D", "s") == pi4 assert pi2.asfreq("h", "s") == pi5 - assert pi2.asfreq("Min", "s") == pi6 + assert pi2.asfreq("min", "s") == pi6 assert pi2.asfreq("s", "s") == pi7 assert pi3.asfreq("Y", "s") == pi1 assert pi3.asfreq("Q", "s") == pi2 assert pi3.asfreq("D", "s") == pi4 assert pi3.asfreq("h", "s") == pi5 - assert pi3.asfreq("Min", "s") == pi6 + assert pi3.asfreq("min", "s") == pi6 assert pi3.asfreq("s", "s") == pi7 assert pi4.asfreq("Y", "s") == pi1 assert pi4.asfreq("Q", "s") == pi2 assert pi4.asfreq("M", "s") == pi3 assert pi4.asfreq("h", "s") == pi5 - assert pi4.asfreq("Min", "s") == pi6 + assert pi4.asfreq("min", "s") == pi6 assert pi4.asfreq("s", "s") == pi7 assert pi5.asfreq("Y", "s") == pi1 assert pi5.asfreq("Q", "s") == pi2 assert pi5.asfreq("M", "s") == pi3 assert pi5.asfreq("D", "s") == pi4 - assert pi5.asfreq("Min", "s") == pi6 + assert pi5.asfreq("min", "s") == pi6 assert pi5.asfreq("s", "s") == pi7 assert pi6.asfreq("Y", "s") == pi1 @@ -66,7 +66,7 @@ def test_asfreq(self): assert pi7.asfreq("M", "s") == pi3 assert pi7.asfreq("D", "s") == pi4 assert pi7.asfreq("h", "s") == pi5 - assert pi7.asfreq("Min", "s") == pi6 + assert pi7.asfreq("min", "s") == pi6 msg = "How must be one of S or E" with pytest.raises(ValueError, match=msg): diff --git a/pandas/tests/indexes/period/test_constructors.py b/pandas/tests/indexes/period/test_constructors.py index 521305e7ffc92..582da2d88676c 100644 --- a/pandas/tests/indexes/period/test_constructors.py +++ b/pandas/tests/indexes/period/test_constructors.py @@ -522,7 +522,7 @@ def test_period_range_length(self): pi = period_range(freq="h", start="1/1/2001", end="12/31/2001 23:00") assert len(pi) == 365 * 24 - pi = period_range(freq="Min", start="1/1/2001", end="1/1/2001 23:59") + pi = period_range(freq="min", start="1/1/2001", end="1/1/2001 23:59") assert len(pi) == 24 * 60 pi = period_range(freq="s", start="1/1/2001", end="1/1/2001 23:59:59") diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 77b8e76894647..e30798dceb328 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -87,7 +87,7 @@ def test_values(self): period_range(freq="M", start="1/1/2001", end="1/1/2002"), period_range(freq="D", start="12/1/2001", end="6/1/2001"), period_range(freq="h", start="12/31/2001", end="1/1/2002 23:00"), - period_range(freq="Min", start="12/31/2001", end="1/1/2002 00:20"), + period_range(freq="min", start="12/31/2001", end="1/1/2002 00:20"), period_range( freq="s", start="12/31/2001 00:00:00", end="12/31/2001 00:05:00" ), diff --git a/pandas/tests/indexes/timedeltas/test_scalar_compat.py b/pandas/tests/indexes/timedeltas/test_scalar_compat.py index 9f0552f8baa90..c08748172fe41 100644 --- a/pandas/tests/indexes/timedeltas/test_scalar_compat.py +++ b/pandas/tests/indexes/timedeltas/test_scalar_compat.py @@ -49,7 +49,7 @@ def test_tdi_total_seconds_all_nat(self): tm.assert_series_equal(result, expected) def test_tdi_round(self): - td = timedelta_range(start="16801 days", periods=5, freq="30Min") + td = timedelta_range(start="16801 days", periods=5, freq="30min") elt = td[1] expected_rng = TimedeltaIndex( diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 112172656b6ec..882a174386d90 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", "QE-DEC", "YE", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30min"] ) def test_tsplot_datetime(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -208,7 +208,7 @@ 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", "QE-DEC", "YE", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30min"] ) def test_line_plot_datetime_series(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -244,7 +244,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", "QE-DEC", "YE", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30min"] ) def test_line_plot_datetime_frame(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -258,7 +258,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", "QE-DEC", "YE", "1B30Min"] + "freq", ["s", "min", "h", "D", "W", "ME", "QE-DEC", "YE", "1B30min"] ) def test_line_plot_inferred_freq(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -572,13 +572,13 @@ def test_finder_annual(self): @pytest.mark.slow def test_finder_minutely(self): nminutes = 50 * 24 * 60 - rng = date_range("1/1/1999", freq="Min", periods=nminutes) + rng = date_range("1/1/1999", freq="min", periods=nminutes) ser = Series(np.random.default_rng(2).standard_normal(len(rng)), rng) _, ax = mpl.pyplot.subplots() ser.plot(ax=ax) xaxis = ax.get_xaxis() rs = xaxis.get_majorticklocs()[0] - xp = Period("1/1/1999", freq="Min").ordinal + xp = Period("1/1/1999", freq="min").ordinal assert rs == xp diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 37b8688f16aac..d55a4e31cc78e 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -43,7 +43,7 @@ def _index_factory(): @pytest.fixture def _index_freq(): - return "Min" + return "min" @pytest.fixture @@ -178,7 +178,7 @@ def test_resample_integerarray(unit): def test_resample_basic_grouper(series, unit): s = series s.index = s.index.as_unit(unit) - result = s.resample("5Min").last() + result = s.resample("5min").last() grouper = Grouper(freq=Minute(5), closed="left", label="left") expected = s.groupby(grouper).agg(lambda x: x.iloc[-1]) tm.assert_series_equal(result, expected) @@ -484,7 +484,7 @@ def test_resample_upsample(unit): s = Series(np.random.default_rng(2).random(len(dti)), dti) # to minutely, by padding - result = s.resample("Min").ffill() + result = s.resample("min").ffill() assert len(result) == 12961 assert result.iloc[0] == s.iloc[0] assert result.iloc[-1] == s.iloc[-1] @@ -541,8 +541,8 @@ def test_upsample_with_limit(unit): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("freq", ["1D", "10h", "5Min", "10s"]) -@pytest.mark.parametrize("rule", ["YE", "3ME", "15D", "30h", "15Min", "30s"]) +@pytest.mark.parametrize("freq", ["1D", "10h", "5min", "10s"]) +@pytest.mark.parametrize("rule", ["YE", "3ME", "15D", "30h", "15min", "30s"]) def test_nearest_upsample_with_limit(tz_aware_fixture, freq, rule, unit): # GH 33939 rng = date_range("1/1/2000", periods=3, freq=freq, tz=tz_aware_fixture).as_unit( @@ -561,7 +561,7 @@ def test_resample_ohlc(series, unit): grouper = Grouper(freq=Minute(5)) expect = s.groupby(grouper).agg(lambda x: x.iloc[-1]) - result = s.resample("5Min").ohlc() + result = s.resample("5min").ohlc() assert len(result) == len(expect) assert len(result.columns) == 4 @@ -1378,8 +1378,8 @@ def test_resample_consistency(unit): s10 = s.reindex(index=i10, method="bfill") s10_2 = s.reindex(index=i10, method="bfill", limit=2) rl = s.reindex_like(s10, method="bfill", limit=2) - r10_2 = s.resample("10Min").bfill(limit=2) - r10 = s.resample("10Min").bfill() + r10_2 = s.resample("10min").bfill(limit=2) + r10 = s.resample("10min").bfill() # s10_2, r10, r10_2, rl should all be equal tm.assert_series_equal(s10_2, r10) @@ -1639,7 +1639,7 @@ def test_resample_dst_anchor(unit): def test_resample_dst_anchor2(unit): dti = date_range( - "2013-09-30", "2013-11-02", freq="30Min", tz="Europe/Paris" + "2013-09-30", "2013-11-02", freq="30min", tz="Europe/Paris" ).as_unit(unit) values = range(dti.size) df = DataFrame({"a": values, "b": values, "c": values}, index=dti, dtype="int64") @@ -1887,14 +1887,14 @@ def f(data, add_arg): @pytest.mark.parametrize( "n1, freq1, n2, freq2", [ - (30, "s", 0.5, "Min"), - (60, "s", 1, "Min"), + (30, "s", 0.5, "min"), + (60, "s", 1, "min"), (3600, "s", 1, "h"), - (60, "Min", 1, "h"), + (60, "min", 1, "h"), (21600, "s", 0.25, "D"), (86400, "s", 1, "D"), (43200, "s", 0.5, "D"), - (1440, "Min", 1, "D"), + (1440, "min", 1, "D"), (12, "h", 0.5, "D"), (24, "h", 1, "D"), ], diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 7e8779ab48b7e..e6a282638df77 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -19,7 +19,7 @@ @pytest.fixture def dti(): - return date_range(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq="Min") + return date_range(start=datetime(2005, 1, 1), end=datetime(2005, 1, 10), freq="min") @pytest.fixture diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 337c5ff53bd14..3816145aed2cc 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -318,7 +318,7 @@ def f(x): def test_apply_columns_multilevel(): # GH 16231 cols = pd.MultiIndex.from_tuples([("A", "a", "", "one"), ("B", "b", "i", "two")]) - ind = date_range(start="2017-01-01", freq="15Min", periods=8) + ind = date_range(start="2017-01-01", freq="15min", periods=8) df = DataFrame(np.array([0] * 16).reshape(8, 2), index=ind, columns=cols) agg_dict = {col: (np.sum if col[3] == "one" else np.mean) for col in df.columns} result = df.resample("h").apply(lambda x: agg_dict[x.name](x)) diff --git a/pandas/tests/scalar/period/test_asfreq.py b/pandas/tests/scalar/period/test_asfreq.py index 4489c307172d7..6b75d1aa1b009 100644 --- a/pandas/tests/scalar/period/test_asfreq.py +++ b/pandas/tests/scalar/period/test_asfreq.py @@ -11,6 +11,7 @@ import pandas._testing as tm bday_msg = "Period with BDay freq is deprecated" +depr_msg = "'{0}' is deprecated and will be removed in a future version" class TestFreqConversion: @@ -79,12 +80,13 @@ def test_conv_annual(self): ival_A_to_D_end = Period(freq="D", year=2007, month=12, day=31) ival_A_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_A_to_H_end = Period(freq="h", year=2007, month=12, day=31, hour=23) - ival_A_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_A_to_T_end = Period( - freq="Min", year=2007, month=12, day=31, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_A_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_A_to_T_end = Period( + freq="Min", year=2007, month=12, day=31, hour=23, minute=59 + ) ival_A_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -157,12 +159,13 @@ def test_conv_quarterly(self): ival_Q_to_D_end = Period(freq="D", year=2007, month=3, day=31) ival_Q_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_Q_to_H_end = Period(freq="h", year=2007, month=3, day=31, hour=23) - ival_Q_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_Q_to_T_end = Period( - freq="Min", year=2007, month=3, day=31, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_Q_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_Q_to_T_end = Period( + freq="Min", year=2007, month=3, day=31, hour=23, minute=59 + ) ival_Q_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -190,8 +193,9 @@ def test_conv_quarterly(self): assert ival_Q.asfreq("D", "E") == ival_Q_to_D_end assert ival_Q.asfreq("h", "s") == ival_Q_to_H_start assert ival_Q.asfreq("h", "E") == ival_Q_to_H_end - assert ival_Q.asfreq("Min", "s") == ival_Q_to_T_start - assert ival_Q.asfreq("Min", "E") == ival_Q_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_Q.asfreq("Min", "s") == ival_Q_to_T_start + assert ival_Q.asfreq("Min", "E") == ival_Q_to_T_end assert ival_Q.asfreq("s", "s") == ival_Q_to_S_start assert ival_Q.asfreq("s", "E") == ival_Q_to_S_end @@ -219,12 +223,13 @@ def test_conv_monthly(self): ival_M_to_D_end = Period(freq="D", year=2007, month=1, day=31) ival_M_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_M_to_H_end = Period(freq="h", year=2007, month=1, day=31, hour=23) - ival_M_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_M_to_T_end = Period( - freq="Min", year=2007, month=1, day=31, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_M_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_M_to_T_end = Period( + freq="Min", year=2007, month=1, day=31, hour=23, minute=59 + ) ival_M_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -246,8 +251,9 @@ def test_conv_monthly(self): assert ival_M.asfreq("D", "E") == ival_M_to_D_end assert ival_M.asfreq("h", "s") == ival_M_to_H_start assert ival_M.asfreq("h", "E") == ival_M_to_H_end - assert ival_M.asfreq("Min", "s") == ival_M_to_T_start - assert ival_M.asfreq("Min", "E") == ival_M_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_M.asfreq("Min", "s") == ival_M_to_T_start + assert ival_M.asfreq("Min", "E") == ival_M_to_T_end assert ival_M.asfreq("s", "s") == ival_M_to_S_start assert ival_M.asfreq("s", "E") == ival_M_to_S_end @@ -309,12 +315,13 @@ def test_conv_weekly(self): ival_W_to_D_end = Period(freq="D", year=2007, month=1, day=7) ival_W_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_W_to_H_end = Period(freq="h", year=2007, month=1, day=7, hour=23) - ival_W_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_W_to_T_end = Period( - freq="Min", year=2007, month=1, day=7, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_W_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_W_to_T_end = Period( + freq="Min", year=2007, month=1, day=7, hour=23, minute=59 + ) ival_W_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -355,8 +362,9 @@ def test_conv_weekly(self): assert ival_W.asfreq("h", "s") == ival_W_to_H_start assert ival_W.asfreq("h", "E") == ival_W_to_H_end - assert ival_W.asfreq("Min", "s") == ival_W_to_T_start - assert ival_W.asfreq("Min", "E") == ival_W_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_W.asfreq("Min", "s") == ival_W_to_T_start + assert ival_W.asfreq("Min", "E") == ival_W_to_T_end assert ival_W.asfreq("s", "s") == ival_W_to_S_start assert ival_W.asfreq("s", "E") == ival_W_to_S_end @@ -402,12 +410,13 @@ def test_conv_business(self): ival_B_to_D = Period(freq="D", year=2007, month=1, day=1) ival_B_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_B_to_H_end = Period(freq="h", year=2007, month=1, day=1, hour=23) - ival_B_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_B_to_T_end = Period( - freq="Min", year=2007, month=1, day=1, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_B_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_B_to_T_end = Period( + freq="Min", year=2007, month=1, day=1, hour=23, minute=59 + ) ival_B_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -428,8 +437,9 @@ def test_conv_business(self): assert ival_B.asfreq("h", "s") == ival_B_to_H_start assert ival_B.asfreq("h", "E") == ival_B_to_H_end - assert ival_B.asfreq("Min", "s") == ival_B_to_T_start - assert ival_B.asfreq("Min", "E") == ival_B_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_B.asfreq("Min", "s") == ival_B_to_T_start + assert ival_B.asfreq("Min", "E") == ival_B_to_T_end assert ival_B.asfreq("s", "s") == ival_B_to_S_start assert ival_B.asfreq("s", "E") == ival_B_to_S_end @@ -468,12 +478,13 @@ def test_conv_daily(self): ival_D_to_H_start = Period(freq="h", year=2007, month=1, day=1, hour=0) ival_D_to_H_end = Period(freq="h", year=2007, month=1, day=1, hour=23) - ival_D_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_D_to_T_end = Period( - freq="Min", year=2007, month=1, day=1, hour=23, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_D_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_D_to_T_end = Period( + freq="Min", year=2007, month=1, day=1, hour=23, minute=59 + ) ival_D_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -506,8 +517,9 @@ def test_conv_daily(self): assert ival_D.asfreq("h", "s") == ival_D_to_H_start assert ival_D.asfreq("h", "E") == ival_D_to_H_end - assert ival_D.asfreq("Min", "s") == ival_D_to_T_start - assert ival_D.asfreq("Min", "E") == ival_D_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_D.asfreq("Min", "s") == ival_D_to_T_start + assert ival_D.asfreq("Min", "E") == ival_D_to_T_end assert ival_D.asfreq("s", "s") == ival_D_to_S_start assert ival_D.asfreq("s", "E") == ival_D_to_S_end @@ -532,12 +544,13 @@ def test_conv_hourly(self): with tm.assert_produces_warning(FutureWarning, match=bday_msg): ival_H_to_B = Period(freq="B", year=2007, month=1, day=1) - ival_H_to_T_start = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0 - ) - ival_H_to_T_end = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_H_to_T_start = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) + ival_H_to_T_end = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=59 + ) ival_H_to_S_start = Period( freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) @@ -559,8 +572,9 @@ def test_conv_hourly(self): assert ival_H.asfreq("B") == ival_H_to_B assert ival_H_end_of_bus.asfreq("B") == ival_H_to_B - assert ival_H.asfreq("Min", "s") == ival_H_to_T_start - assert ival_H.asfreq("Min", "E") == ival_H_to_T_end + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_H.asfreq("Min", "s") == ival_H_to_T_start + assert ival_H.asfreq("Min", "E") == ival_H_to_T_end assert ival_H.asfreq("s", "s") == ival_H_to_S_start assert ival_H.asfreq("s", "E") == ival_H_to_S_end @@ -569,28 +583,29 @@ def test_conv_hourly(self): def test_conv_minutely(self): # frequency conversion tests: from Minutely Frequency" - ival_T = Period(freq="Min", year=2007, month=1, day=1, hour=0, minute=0) - ival_T_end_of_year = Period( - freq="Min", year=2007, month=12, day=31, hour=23, minute=59 - ) - ival_T_end_of_quarter = Period( - freq="Min", year=2007, month=3, day=31, hour=23, minute=59 - ) - ival_T_end_of_month = Period( - freq="Min", year=2007, month=1, day=31, hour=23, minute=59 - ) - ival_T_end_of_week = Period( - freq="Min", year=2007, month=1, day=7, hour=23, minute=59 - ) - ival_T_end_of_day = Period( - freq="Min", year=2007, month=1, day=1, hour=23, minute=59 - ) - ival_T_end_of_bus = Period( - freq="Min", year=2007, month=1, day=1, hour=23, minute=59 - ) - ival_T_end_of_hour = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=59 - ) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_T = Period(freq="Min", year=2007, month=1, day=1, hour=0, minute=0) + ival_T_end_of_year = Period( + freq="Min", year=2007, month=12, day=31, hour=23, minute=59 + ) + ival_T_end_of_quarter = Period( + freq="Min", year=2007, month=3, day=31, hour=23, minute=59 + ) + ival_T_end_of_month = Period( + freq="Min", year=2007, month=1, day=31, hour=23, minute=59 + ) + ival_T_end_of_week = Period( + freq="Min", year=2007, month=1, day=7, hour=23, minute=59 + ) + ival_T_end_of_day = Period( + freq="Min", year=2007, month=1, day=1, hour=23, minute=59 + ) + ival_T_end_of_bus = Period( + freq="Min", year=2007, month=1, day=1, hour=23, minute=59 + ) + ival_T_end_of_hour = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=59 + ) ival_T_to_A = Period(freq="Y", year=2007) ival_T_to_Q = Period(freq="Q", year=2007, quarter=1) @@ -627,7 +642,8 @@ def test_conv_minutely(self): assert ival_T.asfreq("s", "s") == ival_T_to_S_start assert ival_T.asfreq("s", "E") == ival_T_to_S_end - assert ival_T.asfreq("Min") == ival_T + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_T.asfreq("Min") == ival_T def test_conv_secondly(self): # frequency conversion tests: from Secondly Frequency" @@ -666,7 +682,10 @@ def test_conv_secondly(self): with tm.assert_produces_warning(FutureWarning, match=bday_msg): ival_S_to_B = Period(freq="B", year=2007, month=1, day=1) ival_S_to_H = Period(freq="h", year=2007, month=1, day=1, hour=0) - ival_S_to_T = Period(freq="Min", year=2007, month=1, day=1, hour=0, minute=0) + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + ival_S_to_T = Period( + freq="Min", year=2007, month=1, day=1, hour=0, minute=0 + ) assert ival_S.asfreq("Y") == ival_S_to_A assert ival_S_end_of_year.asfreq("Y") == ival_S_to_A @@ -683,8 +702,9 @@ def test_conv_secondly(self): assert ival_S_end_of_bus.asfreq("B") == ival_S_to_B assert ival_S.asfreq("h") == ival_S_to_H assert ival_S_end_of_hour.asfreq("h") == ival_S_to_H - assert ival_S.asfreq("Min") == ival_S_to_T - assert ival_S_end_of_minute.asfreq("Min") == ival_S_to_T + with tm.assert_produces_warning(FutureWarning, match=depr_msg.format("Min")): + assert ival_S.asfreq("Min") == ival_S_to_T + assert ival_S_end_of_minute.asfreq("Min") == ival_S_to_T assert ival_S.asfreq("s") == ival_S diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 967fa9f58a6ff..b99d55de7f0af 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -106,7 +106,7 @@ def test_construction(self): assert i1 == i3 i1 = Period("1982", freq="min") - i2 = Period("1982", freq="Min") + i2 = Period("1982-01-01 00:00") assert i1 == i2 i1 = Period(year=2005, month=3, day=1, freq="D") @@ -141,7 +141,7 @@ def test_construction(self): def test_tuple_freq_disallowed(self): # GH#34703 tuple freq disallowed with pytest.raises(TypeError, match="pass as a string instead"): - Period("1982", freq=("Min", 1)) + Period("1982", freq=("min", 1)) with pytest.raises(TypeError, match="pass as a string instead"): Period("2006-12-31", ("w", 1)) @@ -657,7 +657,7 @@ def test_to_timestamp(self): assert end_ts == p.to_timestamp("D", how=a) assert end_ts == p.to_timestamp("3D", how=a) - from_lst = ["Y", "Q", "M", "W", "B", "D", "h", "Min", "s"] + from_lst = ["Y", "Q", "M", "W", "B", "D", "h", "min", "s"] def _ex(p): if p.freq == "B": @@ -818,7 +818,7 @@ def test_quarterly_negative_ordinals(self): assert isinstance(p, Period) def test_freq_str(self): - i1 = Period("1982", freq="Min") + i1 = Period("1982", freq="min") assert i1.freq == offsets.Minute() assert i1.freqstr == "min" @@ -1063,7 +1063,7 @@ def test_properties_hourly(self): def test_properties_minutely(self): # Test properties on Periods with minutely frequency. - t_date = Period(freq="Min", year=2007, month=1, day=1, hour=0, minute=0) + t_date = Period(freq="min", year=2007, month=1, day=1, hour=0, minute=0) # assert t_date.quarter == 1 assert t_date.month == 1 @@ -1081,7 +1081,7 @@ def test_properties_minutely(self): def test_properties_secondly(self): # Test properties on Periods with secondly frequency. s_date = Period( - freq="Min", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="min", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) # assert s_date.year == 2007 @@ -1096,7 +1096,7 @@ def test_properties_secondly(self): assert s_date.days_in_month == 31 assert ( Period( - freq="Min", year=2012, month=2, day=1, hour=0, minute=0, second=0 + freq="min", year=2012, month=2, day=1, hour=0, minute=0, second=0 ).days_in_month == 29 ) diff --git a/pandas/tests/scalar/timestamp/methods/test_round.py b/pandas/tests/scalar/timestamp/methods/test_round.py index d10ee18b47f19..cb32092b4c35e 100644 --- a/pandas/tests/scalar/timestamp/methods/test_round.py +++ b/pandas/tests/scalar/timestamp/methods/test_round.py @@ -60,7 +60,7 @@ def test_round_tzaware(self): def test_round_30min(self): # round dt = Timestamp("20130104 12:32:00") - result = dt.round("30Min") + result = dt.round("30min") expected = Timestamp("20130104 12:30:00") assert result == expected diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 4fc97bc3969df..248af503bc5de 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -857,10 +857,10 @@ def test_rule_code(self): def test_freq_offsets(): off = BDay(1, offset=timedelta(0, 1800)) - assert off.freqstr == "B+30Min" + assert off.freqstr == "B+30min" off = BDay(1, offset=timedelta(0, -1800)) - assert off.freqstr == "B-30Min" + assert off.freqstr == "B-30min" class TestReprNames: From 3cc94d255b1498eb8d383a072e2592204758965c Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Fri, 15 Dec 2023 23:35:16 +0100 Subject: [PATCH 10/21] correct docs --- doc/source/user_guide/10min.rst | 2 +- doc/source/user_guide/timeseries.rst | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/source/user_guide/10min.rst b/doc/source/user_guide/10min.rst index c8e67710c85a9..31bb358b51b88 100644 --- a/doc/source/user_guide/10min.rst +++ b/doc/source/user_guide/10min.rst @@ -612,7 +612,7 @@ financial applications. See the :ref:`Time Series section `. rng = pd.date_range("1/1/2012", periods=100, freq="s") ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng) - ts.resample("5Min").sum() + ts.resample("5min").sum() :meth:`Series.tz_localize` localizes a time series to a time zone: diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 105d11b67c9bf..76e2b28c9daf1 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -1645,7 +1645,7 @@ Basics ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng) - ts.resample("5Min").sum() + ts.resample("5min").sum() The ``resample`` function is very flexible and allows you to specify many different parameters to control the frequency conversion and resampling @@ -1657,11 +1657,11 @@ a method of the returned object, including ``sum``, ``mean``, ``std``, ``sem``, .. ipython:: python - ts.resample("5Min").mean() + ts.resample("5min").mean() - ts.resample("5Min").ohlc() + ts.resample("5min").ohlc() - ts.resample("5Min").max() + ts.resample("5min").max() For downsampling, ``closed`` can be set to 'left' or 'right' to specify which @@ -1669,9 +1669,9 @@ end of the interval is closed: .. ipython:: python - ts.resample("5Min", closed="right").mean() + ts.resample("5min", closed="right").mean() - ts.resample("5Min", closed="left").mean() + ts.resample("5min", closed="left").mean() Parameters like ``label`` are used to manipulate the resulting labels. ``label`` specifies whether the result is labeled with the beginning or @@ -1679,9 +1679,9 @@ the end of the interval. .. ipython:: python - ts.resample("5Min").mean() # by default label='left' + ts.resample("5min").mean() # by default label='left' - ts.resample("5Min", label="left").mean() + ts.resample("5min", label="left").mean() .. warning:: From 457ae966c34d5b739e53ee2c5a002ee1500d5fb2 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 19 Dec 2023 23:42:34 +0100 Subject: [PATCH 11/21] show depr warning in test_construction() for Period --- pandas/tests/scalar/period/test_period.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index b99d55de7f0af..9c0cbac86ac17 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -106,7 +106,10 @@ def test_construction(self): assert i1 == i3 i1 = Period("1982", freq="min") - i2 = Period("1982-01-01 00:00") + msg = "'MIN' is deprecated and will be removed in a " + "future version. Please use 'min' instead." + with tm.assert_produces_warning(FutureWarning, match=msg): + i2 = Period("1982", freq="MIN") assert i1 == i2 i1 = Period(year=2005, month=3, day=1, freq="D") From f7095575ea260e89695c46076e31ae7d838cc3f4 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 20 Dec 2023 13:41:20 +0100 Subject: [PATCH 12/21] correct warning message in test_construction() --- pandas/tests/scalar/period/test_period.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 9c0cbac86ac17..2abb97b0371a5 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -106,8 +106,7 @@ def test_construction(self): assert i1 == i3 i1 = Period("1982", freq="min") - msg = "'MIN' is deprecated and will be removed in a " - "future version. Please use 'min' instead." + msg = "'MIN' is deprecated and will be removed in a future version." with tm.assert_produces_warning(FutureWarning, match=msg): i2 = Period("1982", freq="MIN") assert i1 == i2 From 7cd909f77f9a5851c28c8f3d8fcdcfd2ee8c81d9 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 20 Dec 2023 14:15:33 +0100 Subject: [PATCH 13/21] remove from to_offset() unnecessary check, fix test_to_offset_invalid --- pandas/_libs/tslibs/offsets.pyx | 19 ++++++++----------- pandas/tests/tslibs/test_to_offset.py | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index dca5123d911b1..2c1da88b83c5f 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4784,17 +4784,14 @@ 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.upper() in c_OFFSET_DEPR_FREQSTR: - if n > 0 or stride == "-": - name = name - else: - warnings.warn( - f"\'{name}\' is deprecated and will be removed " - f"in a future version, please use " - f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - name = c_OFFSET_DEPR_FREQSTR[name.upper()] + warnings.warn( + f"\'{name}\' is deprecated and will be removed " + f"in a future version, please use " + f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = c_OFFSET_DEPR_FREQSTR[name.upper()] elif (is_period is False and name != name.upper() and name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR): diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index eac100486c6d2..b987a5da293be 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -48,7 +48,7 @@ def test_to_offset_negative(freqstr, expected): @pytest.mark.parametrize( "freqstr", [ - "2h20m", + "2h20ME", "us1", "-us", "3us1", @@ -64,7 +64,7 @@ def test_to_offset_negative(freqstr, expected): "+1", "-7", "+d", - "-m", + "-ME", # Invalid shortcut anchors. "SME-0", "SME-28", From 8d1d6dd5324120f1b5674389f0fb47b85ae55046 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 20 Dec 2023 14:29:23 +0100 Subject: [PATCH 14/21] fix pre-commit error --- pandas/_libs/tslibs/offsets.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 2c1da88b83c5f..c4afb0a31fe69 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4786,7 +4786,7 @@ cpdef to_offset(freq, bint is_period=False): if is_period is False and name.upper() in c_OFFSET_DEPR_FREQSTR: warnings.warn( f"\'{name}\' is deprecated and will be removed " - f"in a future version, please use " + f"in a future version, please use " f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", FutureWarning, stacklevel=find_stack_level(), From 286b61855677817ac1e7ee56c1f1f4cdb23bd065 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 21 Dec 2023 10:43:26 +0100 Subject: [PATCH 15/21] add notes to /v2.2.0.rst --- doc/source/whatsnew/v2.2.0.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 8c475791df64d..d0b6d249a1cc3 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -408,6 +408,22 @@ For example: pd.date_range('2020-01-01', periods=3, freq='QE-NOV') +Deprecate lowercase strings ``w``, ``m``, ``q``, etc. in favour of ``W``, ``M``, ``Q``, etc. for time series, period, and timedelta +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Deprecated lowercase strings in favour of uppercase strings denoting (:issue:`56346`): +- period aliases weekly, monthly and bigger frequency +- offsets aliases representing :class:`DateOffset` subclasses that are a week or bigger (``Week``, ``MonthBegin``, ``MonthEnd``, etc.) +- timedelta units week, month or bigger + +Deprecate uppercase strings ``H`, ``S``, etc. in favour of ``h``, ``s``, etc. for time series, period, and timedelta +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Deprecated uppercase strings in favour of lowercase strings denoting (:issue:`56346`): +- period aliases hourly, minutely or smaller frequency +- offsets aliases representing :class:`DateOffset` subclasses that are an hour or smaller (``Hour``, ``Minute``, etc.) +- timedelta units hour, minute or smaller + Deprecated automatic downcasting ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 606d0c5101e50b6f7c6b6b738b5dc871ab930be1 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 21 Dec 2023 13:35:16 +0100 Subject: [PATCH 16/21] add filterwarnings to test_to_offset_invalid, correct notes in v2.2.0.rst --- doc/source/whatsnew/v2.2.0.rst | 35 +++++++++++++++++++++------ pandas/tests/tslibs/test_to_offset.py | 7 ++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index d0b6d249a1cc3..1dc4a80804069 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -408,21 +408,40 @@ For example: pd.date_range('2020-01-01', periods=3, freq='QE-NOV') -Deprecate lowercase strings ``w``, ``m``, ``q``, etc. in favour of ``W``, ``M``, ``Q``, etc. for time series, period, and timedelta -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Deprecate lowercase strings ``w``, ``m``, ``q``, etc. and uppercase strings ``H``, ``MIN``, ``S``, etc. for time series, period, and timedelta +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Previously, both ``'h'`` and ``'H'`` would allowed for 'hour' offset/period alias. We now require the case to be correct - check the :ref:`offset aliases ` and the :ref:`period aliases ` parts of the docs and make sure you're using the correct one (:issue:`56346`) + +Deprecated lowercase strings in favour of uppercase strings denoting: -Deprecated lowercase strings in favour of uppercase strings denoting (:issue:`56346`): - period aliases weekly, monthly and bigger frequency - offsets aliases representing :class:`DateOffset` subclasses that are a week or bigger (``Week``, ``MonthBegin``, ``MonthEnd``, etc.) -- timedelta units week, month or bigger +- timedelta units for week, month or bigger -Deprecate uppercase strings ``H`, ``S``, etc. in favour of ``h``, ``s``, etc. for time series, period, and timedelta -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Deprecated uppercase strings in favour of lowercase strings denoting: -Deprecated uppercase strings in favour of lowercase strings denoting (:issue:`56346`): - period aliases hourly, minutely or smaller frequency - offsets aliases representing :class:`DateOffset` subclasses that are an hour or smaller (``Hour``, ``Minute``, etc.) -- timedelta units hour, minute or smaller +- timedelta units for hour, minute or smaller + +For example: + +*Previous behavior*: + +.. code-block:: ipython + + In [9]: pd.date_range('2020-01-01', periods=3, freq='H') + Out[9]: + DatetimeIndex(['2020-01-01 00:00:00', '2020-01-01 01:00:00', + '2020-01-01 02:00:00'], + dtype='datetime64[ns]', freq='H') + +*Future behavior*: + +.. ipython:: python + + pd.date_range('2020-01-01', periods=3, freq='h') Deprecated automatic downcasting ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index b987a5da293be..e6893bd09aefa 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -45,10 +45,13 @@ def test_to_offset_negative(freqstr, expected): assert result.n == expected +@pytest.mark.filterwarnings( + "ignore:'m' is deprecated and will be removed in a future version.:FutureWarning" +) @pytest.mark.parametrize( "freqstr", [ - "2h20ME", + "2h20m", "us1", "-us", "3us1", @@ -64,7 +67,7 @@ def test_to_offset_negative(freqstr, expected): "+1", "-7", "+d", - "-ME", + "-m", # Invalid shortcut anchors. "SME-0", "SME-28", From 32993a90e98d2d3d0ee6ee647ffd9d2cd46a674f Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 21 Dec 2023 13:51:28 +0100 Subject: [PATCH 17/21] improve the headline in v2.2.0.rst --- doc/source/whatsnew/v2.2.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 1dc4a80804069..13e5d356a518f 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -408,8 +408,8 @@ For example: pd.date_range('2020-01-01', periods=3, freq='QE-NOV') -Deprecate lowercase strings ``w``, ``m``, ``q``, etc. and uppercase strings ``H``, ``MIN``, ``S``, etc. for time series, period, and timedelta -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Deprecate lowercase strings ``'w'``, ``'m'``, ``'q'``, etc. and uppercase strings ``'H'``, ``'MIN'``, ``'S'``, etc. for time series, period, and timedelta +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Previously, both ``'h'`` and ``'H'`` would allowed for 'hour' offset/period alias. We now require the case to be correct - check the :ref:`offset aliases ` and the :ref:`period aliases ` parts of the docs and make sure you're using the correct one (:issue:`56346`) From dcf1994374a58df0afbab16b93a84992f463a31f Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 21 Dec 2023 18:57:56 +0100 Subject: [PATCH 18/21] correct depr note in v2.2.0.rst --- doc/source/whatsnew/v2.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 13e5d356a518f..20597ad461d2b 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -411,7 +411,7 @@ For example: Deprecate lowercase strings ``'w'``, ``'m'``, ``'q'``, etc. and uppercase strings ``'H'``, ``'MIN'``, ``'S'``, etc. for time series, period, and timedelta ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Previously, both ``'h'`` and ``'H'`` would allowed for 'hour' offset/period alias. We now require the case to be correct - check the :ref:`offset aliases ` and the :ref:`period aliases ` parts of the docs and make sure you're using the correct one (:issue:`56346`) +Previously, both ``'h'`` and ``'H'`` were allowed for 'hour' offset/period alias. We now require the case to be correct - check the :ref:`offset aliases ` and the :ref:`period aliases ` parts of the docs and make sure you're using the correct one (:issue:`56346`) Deprecated lowercase strings in favour of uppercase strings denoting: From 7889c7df19fb2b6a5495c3eafe4d65c634ad26b8 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 27 Dec 2023 23:48:27 +0100 Subject: [PATCH 19/21] correct to_offset() for freqs such us ys, qs, and add tests --- pandas/_libs/tslibs/offsets.pyx | 11 ++--- pandas/tests/arrays/test_datetimes.py | 41 +++++++++-------- .../tests/indexes/period/test_period_range.py | 35 ++++----------- .../timedeltas/test_timedelta_range.py | 18 ++------ pandas/tests/scalar/period/test_period.py | 12 ++--- pandas/tests/tslibs/test_to_offset.py | 44 +++++++++++++++++++ 6 files changed, 89 insertions(+), 72 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 09a46c6ea85f2..223c7d17a94fe 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4794,7 +4794,7 @@ 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.upper() in c_OFFSET_DEPR_FREQSTR: + if not is_period and name.upper() in c_OFFSET_DEPR_FREQSTR: warnings.warn( f"\'{name}\' is deprecated and will be removed " f"in a future version, please use " @@ -4803,9 +4803,10 @@ cpdef to_offset(freq, bint is_period=False): stacklevel=find_stack_level(), ) name = c_OFFSET_DEPR_FREQSTR[name.upper()] - elif (is_period is False and + if (not is_period and name != name.upper() and - name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR): + name.lower() not in {"s", "ms", "us", "ns"} and + name.upper().split("-")[0].endswith(("S", "E"))): warnings.warn( f"\'{name}\' is deprecated and will be removed " f"in a future version, please use " @@ -4814,7 +4815,7 @@ cpdef to_offset(freq, bint is_period=False): stacklevel=find_stack_level(), ) name = name.upper() - if is_period is True and name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR: + if is_period and name.upper() in c_REVERSE_OFFSET_DEPR_FREQSTR: if name.upper().startswith("Y"): raise ValueError( f"for Period, please use \'Y{name.upper()[2:]}\' " @@ -4830,7 +4831,7 @@ cpdef to_offset(freq, bint is_period=False): f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name.upper())}\' " f"instead of \'{name}\'" ) - elif is_period is True and name.upper() in c_OFFSET_DEPR_FREQSTR: + elif is_period and name.upper() in c_OFFSET_DEPR_FREQSTR: if name.upper().startswith("A"): warnings.warn( f"\'{name}\' is deprecated and will be removed in a future " diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 7e9413372cd37..d46dd7617c6e6 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -766,12 +766,16 @@ def test_iter_zoneinfo_fold(self, tz): "freq, freq_depr", [ ("2ME", "2M"), + ("2SME", "2SM"), ("2QE", "2Q"), ("2QE-SEP", "2Q-SEP"), ("1YE", "1Y"), ("2YE-MAR", "2Y-MAR"), ("1YE", "1A"), ("2YE-MAR", "2A-MAR"), + ("2ME", "2m"), + ("2QE-SEP", "2q-sep"), + ("2YE-MAR", "2a-mar"), ], ) def test_date_range_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr): @@ -784,39 +788,38 @@ def test_date_range_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr): result = pd.date_range("1/1/2000", periods=4, freq=freq_depr) tm.assert_index_equal(result, expected) - @pytest.mark.parametrize( - "freq, freq_depr", - [ - ("2h", "2H"), - ("2s", "2S"), - ], - ) - def test_date_range_uppercase_frequency_deprecated(self, freq, freq_depr): + @pytest.mark.parametrize("freq_depr", ["2H", "2CBH", "2MIN", "2S", "2mS", "2Us"]) + def test_date_range_uppercase_frequency_deprecated(self, freq_depr): # GH#9586, GH#54939 depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " - f"future version. Please use '{freq[1:]}' instead." + f"future version. Please use '{freq_depr.lower()[1:]}' instead." - expected = pd.date_range("1/1/2000", periods=4, freq=freq) + expected = pd.date_range("1/1/2000", periods=4, freq=freq_depr.lower()) with tm.assert_produces_warning(FutureWarning, match=depr_msg): result = pd.date_range("1/1/2000", periods=4, freq=freq_depr) tm.assert_index_equal(result, expected) @pytest.mark.parametrize( - "freq, freq_depr", + "freq_depr", [ - ("2ME", "2me"), - ("2ME", "2m"), - ("2QE-SEP", "2q-sep"), - ("2W", "2w"), - ("2min", "2MIN"), + "2ye-mar", + "2ys", + "2qe", + "2qs-feb", + "2bqs", + "2sms", + "2bms", + "2cbme", + "2me", + "2w", ], ) - def test_date_range_lowercase_frequency_deprecated(self, freq, freq_depr): + def test_date_range_lowercase_frequency_deprecated(self, freq_depr): # GH#9586, GH#54939 depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " - f"future version, please use '{freq[1:]}' instead." + f"future version, please use '{freq_depr.upper()[1:]}' instead." - expected = pd.date_range("1/1/2000", periods=4, freq=freq) + expected = pd.date_range("1/1/2000", periods=4, freq=freq_depr.upper()) with tm.assert_produces_warning(FutureWarning, match=depr_msg): result = pd.date_range("1/1/2000", periods=4, freq=freq_depr) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/indexes/period/test_period_range.py b/pandas/tests/indexes/period/test_period_range.py index 2f45af589835c..1a02df9789706 100644 --- a/pandas/tests/indexes/period/test_period_range.py +++ b/pandas/tests/indexes/period/test_period_range.py @@ -220,39 +220,20 @@ def test_a_deprecated_from_time_series(self, freq, freq_depr): with tm.assert_produces_warning(FutureWarning, match=msg): period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009") - @pytest.mark.parametrize( - "freq, freq_depr", - [ - ("2M", "2m"), - ("2Q-SEP", "2q-sep"), - ("2Y", "2y"), - ("2W", "2w"), - ("2min", "2MIN"), - ("2s", "2S"), - ("2h", "2H"), - ], - ) - def test_lower_uppercase_freq_deprecated_from_time_series(self, freq, freq_depr): + @pytest.mark.parametrize("freq_depr", ["2H", "2MIN", "2S", "2mS", "2Us", "2NS"]) + def test_lower_uppercase_freq_deprecated_from_time_series(self, freq_depr): # GH#52536, GH#54939, ,GH#56346 msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " - f"future version. Please use '{freq[1:]}' instead." + f"future version. Please use '{freq_depr.lower()[1:]}' instead." with tm.assert_produces_warning(FutureWarning, match=msg): - period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009") + period_range("2020-01-01 00:00:00 00:00", periods=2, freq=freq_depr) - @pytest.mark.parametrize( - "freq, freq_depr", - [ - ("2us", "2US"), - ("2ns", "2NS"), - ("2us", "2uS"), - ("2ns", "2Ns"), - ], - ) - def test_mixcase_us_ns_deprecated_from_time_series(self, freq, freq_depr): + @pytest.mark.parametrize("freq_depr", ["2m", "2q-sep", "2y", "2w"]) + def test_lower_lowercase_freq_deprecated_from_time_series(self, freq_depr): # GH#52536, GH#54939, ,GH#56346 msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " - f"future version. Please use '{freq[1:]}' instead." + f"future version. Please use '{freq_depr.upper()[1:]}' instead." with tm.assert_produces_warning(FutureWarning, match=msg): - period_range("2020-01-01 00:00:00 00:00", periods=2, freq=freq_depr) + period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009") diff --git a/pandas/tests/indexes/timedeltas/test_timedelta_range.py b/pandas/tests/indexes/timedeltas/test_timedelta_range.py index 10be3d50aa08a..a4999dd2e609d 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta_range.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta_range.py @@ -88,22 +88,10 @@ def test_timedelta_range_H_T_deprecated(self, freq, msg_freq): expected = timedelta_range(start="0 days", end="4 days", freq=freq) tm.assert_index_equal(result, expected) - @pytest.mark.parametrize( - "freq_depr, freq", - [ - ("H", "h"), - ("MIN", "min"), - ("Min", "min"), - ("S", "s"), - ("US", "us"), - ("NS", "ns"), - ("uS", "us"), - ("Ns", "ns"), - ], - ) - def test_timedelta_range_uppercase_freq_deprecated(self, freq, freq_depr): + @pytest.mark.parametrize("freq_depr", ["H", "MIN", "Min", "S", "Us", "NS"]) + def test_timedelta_range_uppercase_freq_deprecated(self, freq_depr): # GH#56346 - expected = to_timedelta(np.arange(5), unit=freq) + expected = to_timedelta(np.arange(5), unit=freq_depr.lower()) to_timedelta(np.arange(5), unit="m") with tm.assert_produces_warning(FutureWarning, match=freq_depr): result = to_timedelta(np.arange(5), unit=freq_depr) diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 2abb97b0371a5..0f3fc75fc3343 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -1106,13 +1106,13 @@ def test_properties_secondly(self): @pytest.mark.parametrize( "freq, freq_depr", [ + ("2W", "2w"), ("2M", "2m"), - ("2Q", "2m"), - ("2Y-SEP", "2q-sep"), + ("2Q", "2q"), + ("2Y-SEP", "2y-sep"), ("2h", "2H"), ("2s", "2S"), ("2us", "2US"), - ("2us", "2US"), ("2ns", "2NS"), ], ) @@ -1122,10 +1122,10 @@ def test_period_upperlowercase_frequency_deprecated(self, freq, freq_depr): f"future version. Please use '{freq[1:]}' instead." with tm.assert_produces_warning(FutureWarning, match=depr_msg): - Period("2016-03-01 09:00", freq=freq_depr) + p1 = Period("2016-03-01 09:00", freq=freq_depr) - p1 = Period("2016-03-01 09:00", freq=freq) - assert isinstance(p1, Period) + p2 = Period("2016-03-01 09:00", freq=freq) + assert p1 == p2 class TestPeriodComparisons: diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index e6893bd09aefa..25a7e3b8c3f30 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -175,3 +175,47 @@ def test_to_offset_pd_timedelta(kwargs, expected): def test_anchored_shortcuts(shortcut, expected): result = to_offset(shortcut) assert result == expected + + +@pytest.mark.parametrize( + "freq_depr", + [ + "2ye-mar", + "2ys", + "2qe", + "2qs-feb", + "2bqs", + "2sms", + "2bms", + "2cbme", + "2me", + "2w", + ], +) +def test_to_offset_lowercase_frequency_deprecated(freq_depr): + # GH#54939, GH#56346 + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " + f"future version, please use '{freq_depr.upper()[1:]}' instead." + + with pytest.raises(FutureWarning, match=depr_msg): + to_offset(freq_depr) + + +@pytest.mark.parametrize( + "freq_depr", + [ + "2H", + "2BH", + "2MIN", + "2S", + "2Us", + "2NS", + ], +) +def test_to_offset_uppercase_frequency_deprecated(freq_depr): + # GH#54939, GH#56346 + depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a " + f"future version, please use '{freq_depr.lower()[1:]}' instead." + + with pytest.raises(FutureWarning, match=depr_msg): + to_offset(freq_depr) From 530f0566a06978ef247f8a5c6ec3f85126bc6af9 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 8 Feb 2024 09:57:32 +0100 Subject: [PATCH 20/21] deprecate lowercase freq 'w', 'd' from timeseries --- pandas/_libs/tslibs/offsets.pyx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 3435794c63b49..d5093db86bc69 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4912,7 +4912,15 @@ cpdef to_offset(freq, bint is_period=False): stacklevel=find_stack_level(), ) name = c_OFFSET_DEPR_FREQSTR.get(name.upper()) - + if name == "w"or name == "d": + warnings.warn( + f"\'{name}\' is deprecated and will be removed in " + f"a future version, please use \'{name.upper()}\' " + f"instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + name = name.upper() if sep != "" and not sep.isspace(): raise ValueError("separator must be spaces") prefix = _lite_rule_alias.get(name) or name From f6005384504b52447e52e90bf0296fe01515e87a Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 8 Feb 2024 10:42:35 +0100 Subject: [PATCH 21/21] fix tests for 'D' --- pandas/tests/frame/methods/test_astype.py | 4 +-- pandas/tests/frame/methods/test_reindex.py | 4 ++- pandas/tests/io/formats/test_to_csv.py | 4 ++- .../tests/io/json/test_json_table_schema.py | 28 +++++++++---------- pandas/tests/scalar/period/test_period.py | 4 ++- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index 84e642f47417b..395fce5629724 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -716,7 +716,7 @@ def test_astype_ignores_errors_for_extension_dtypes(self, data, dtype, errors): def test_astype_tz_conversion(self): # GH 35973 - val = {"tz": date_range("2020-08-30", freq="d", periods=2, tz="Europe/London")} + val = {"tz": date_range("2020-08-30", freq="D", periods=2, tz="Europe/London")} df = DataFrame(val) result = df.astype({"tz": "datetime64[ns, Europe/Berlin]"}) @@ -727,7 +727,7 @@ def test_astype_tz_conversion(self): @pytest.mark.parametrize("tz", ["UTC", "Europe/Berlin"]) def test_astype_tz_object_conversion(self, tz): # GH 35973 - val = {"tz": date_range("2020-08-30", freq="d", periods=2, tz="Europe/London")} + val = {"tz": date_range("2020-08-30", freq="D", periods=2, tz="Europe/London")} expected = DataFrame(val) # convert expected to object dtype from other tz str (independently tested) diff --git a/pandas/tests/frame/methods/test_reindex.py b/pandas/tests/frame/methods/test_reindex.py index 76d80e87bdeb5..f4211f6ca67ad 100644 --- a/pandas/tests/frame/methods/test_reindex.py +++ b/pandas/tests/frame/methods/test_reindex.py @@ -787,7 +787,9 @@ def test_reindex_axes(self): index=[datetime(2012, 1, 1), datetime(2012, 1, 2), datetime(2012, 1, 3)], columns=["a", "b", "c"], ) - time_freq = date_range("2012-01-01", "2012-01-03", freq="d") + msg = "'d' is deprecated and will be removed in a future version." + with tm.assert_produces_warning(FutureWarning, match=msg): + time_freq = date_range("2012-01-01", "2012-01-03", freq="d") some_cols = ["a", "b"] index_freq = df.reindex(index=time_freq).index.freq diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 49776d532db1d..c6d4bd02f54d0 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -221,7 +221,9 @@ def test_to_csv_na_rep_nullable_string(self, nullable_string_dtype): def test_to_csv_date_format(self): # GH 10209 df_sec = DataFrame({"A": pd.date_range("20130101", periods=5, freq="s")}) - df_day = DataFrame({"A": pd.date_range("20130101", periods=5, freq="d")}) + msg = "'d' is deprecated and will be removed in a future version." + with tm.assert_produces_warning(FutureWarning, match=msg): + df_day = DataFrame({"A": pd.date_range("20130101", periods=5, freq="d")}) expected_rows = [ ",A", diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index b6fa90edbf106..f35f93af0279a 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -31,7 +31,7 @@ def df_schema(): { "A": [1, 2, 3, 4], "B": ["a", "b", "c", "c"], - "C": pd.date_range("2016-01-01", freq="d", periods=4), + "C": pd.date_range("2016-01-01", freq="D", periods=4), "D": pd.timedelta_range("1h", periods=4, freq="min"), }, index=pd.Index(range(4), name="idx"), @@ -44,12 +44,12 @@ def df_table(): { "A": [1, 2, 3, 4], "B": ["a", "b", "c", "c"], - "C": pd.date_range("2016-01-01", freq="d", periods=4), + "C": pd.date_range("2016-01-01", freq="D", periods=4), "D": pd.timedelta_range("1h", periods=4, freq="min"), "E": pd.Series(pd.Categorical(["a", "b", "c", "c"])), "F": pd.Series(pd.Categorical(["a", "b", "c", "c"], ordered=True)), "G": [1.0, 2.0, 3, 4.0], - "H": pd.date_range("2016-01-01", freq="d", periods=4, tz="US/Central"), + "H": pd.date_range("2016-01-01", freq="D", periods=4, tz="US/Central"), }, index=pd.Index(range(4), name="idx"), ) @@ -681,7 +681,7 @@ class TestTableOrientReader: {"ints": [1, 2, 3, 4]}, {"objects": ["a", "b", "c", "d"]}, {"objects": ["1", "2", "3", "4"]}, - {"date_ranges": pd.date_range("2016-01-01", freq="d", periods=4)}, + {"date_ranges": pd.date_range("2016-01-01", freq="D", periods=4)}, {"categoricals": pd.Series(pd.Categorical(["a", "b", "c", "c"]))}, { "ordered_cats": pd.Series( @@ -693,7 +693,7 @@ class TestTableOrientReader: {"bools": [True, False, False, True]}, { "timezones": pd.date_range( - "2016-01-01", freq="d", periods=4, tz="US/Central" + "2016-01-01", freq="D", periods=4, tz="US/Central" ) # added in # GH 35973 }, ], @@ -732,7 +732,7 @@ def test_read_json_table_orient_raises(self, index_nm): {"ints": [1, 2, 3, 4]}, {"objects": ["a", "b", "c", "d"]}, {"objects": ["1", "2", "3", "4"]}, - {"date_ranges": pd.date_range("2016-01-01", freq="d", periods=4)}, + {"date_ranges": pd.date_range("2016-01-01", freq="D", periods=4)}, {"categoricals": pd.Series(pd.Categorical(["a", "b", "c", "c"]))}, { "ordered_cats": pd.Series( @@ -744,7 +744,7 @@ def test_read_json_table_orient_raises(self, index_nm): {"bools": [True, False, False, True]}, { "timezones": pd.date_range( - "2016-01-01", freq="d", periods=4, tz="US/Central" + "2016-01-01", freq="D", periods=4, tz="US/Central" ) # added in # GH 35973 }, ], @@ -766,15 +766,15 @@ def test_read_json_table_period_orient(self, index_nm, vals): pd.Index(range(4)), pd.date_range( "2020-08-30", - freq="d", + freq="D", periods=4, )._with_freq(None), pd.date_range( - "2020-08-30", freq="d", periods=4, tz="US/Central" + "2020-08-30", freq="D", periods=4, tz="US/Central" )._with_freq(None), pd.MultiIndex.from_product( [ - pd.date_range("2020-08-30", freq="d", periods=2, tz="US/Central"), + pd.date_range("2020-08-30", freq="D", periods=2, tz="US/Central"), ["x", "y"], ], ), @@ -784,10 +784,10 @@ def test_read_json_table_period_orient(self, index_nm, vals): "vals", [ {"floats": [1.1, 2.2, 3.3, 4.4]}, - {"dates": pd.date_range("2020-08-30", freq="d", periods=4)}, + {"dates": pd.date_range("2020-08-30", freq="D", periods=4)}, { "timezones": pd.date_range( - "2020-08-30", freq="d", periods=4, tz="Europe/London" + "2020-08-30", freq="D", periods=4, tz="Europe/London" ) }, ], @@ -804,12 +804,12 @@ def test_comprehensive(self): { "A": [1, 2, 3, 4], "B": ["a", "b", "c", "c"], - "C": pd.date_range("2016-01-01", freq="d", periods=4), + "C": pd.date_range("2016-01-01", freq="D", periods=4), # 'D': pd.timedelta_range('1h', periods=4, freq='min'), "E": pd.Series(pd.Categorical(["a", "b", "c", "c"])), "F": pd.Series(pd.Categorical(["a", "b", "c", "c"], ordered=True)), "G": [1.1, 2.2, 3.3, 4.4], - "H": pd.date_range("2016-01-01", freq="d", periods=4, tz="US/Central"), + "H": pd.date_range("2016-01-01", freq="D", periods=4, tz="US/Central"), "I": [True, False, False, True], }, index=pd.Index(range(4), name="idx"), diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index c7592e980c5cf..0ae6796e8682f 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -117,7 +117,9 @@ def test_construction(self): i2 = Period("3/1/2005", freq="D") assert i1 == i2 - i3 = Period(year=2005, month=3, day=1, freq="d") + msg = "'d' is deprecated and will be removed in a future version." + with tm.assert_produces_warning(FutureWarning, match=msg): + i3 = Period(year=2005, month=3, day=1, freq="d") assert i1 == i3 i1 = Period("2007-01-01 09:00:00.001")