From 761ac0e839f34606e5e4f0b08f450cbb3a48504b Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Mon, 25 Aug 2025 04:26:39 +0530 Subject: [PATCH 1/4] DOC: Clarify list-like vs scalar in Series.eq docstring --- pandas/core/series.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index b40e71f2b5b42..52a045c2d0f37 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6072,7 +6072,9 @@ def eq( Parameters ---------- other : Series or scalar value - The second operand in this operation. + The second operand in this operation. Only `np.ndarray`, `list`, `tuple`, + and `Series` are considered "list-like" by pandas. All other types will + be treated as scalar values. level : int or name Broadcast across a level, matching Index values on the passed MultiIndex level. From 9296b6e59f390b8cd48d6e68e567133c3773168e Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 6 Sep 2025 11:32:18 +0530 Subject: [PATCH 2/4] ERR: Improve error message for deprecated frequency aliases --- .../tseries/frequencies/test_frequencies.py | 8 +++++++ pandas/tseries/frequencies.py | 23 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pandas/tests/tseries/frequencies/test_frequencies.py b/pandas/tests/tseries/frequencies/test_frequencies.py index f0af290b2fb69..ebf3f5c697c9d 100644 --- a/pandas/tests/tseries/frequencies/test_frequencies.py +++ b/pandas/tests/tseries/frequencies/test_frequencies.py @@ -2,6 +2,8 @@ from pandas._libs.tslibs import offsets +import pandas as pd + from pandas.tseries.frequencies import ( is_subperiod, is_superperiod, @@ -27,3 +29,9 @@ def test_super_sub_symmetry(p1, p2, expected): assert is_superperiod(p1, p2) is expected assert is_subperiod(p2, p1) is expected + + +def test_deprecated_freq_alias_error(): + # GH#62259 + with pytest.raises(ValueError, match="Invalid frequency 'H'.*Did you mean 'h'?"): + pd.date_range("2012-01-01", periods=3, freq="H") diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index 88ea1bfa3c6ed..533f0889c1625 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -27,7 +27,7 @@ from pandas._libs.tslibs.offsets import ( DateOffset, Day, - to_offset, + to_offset as _to_offset, ) from pandas._libs.tslibs.parsing import get_rule_month from pandas.util._decorators import cache_readonly @@ -53,6 +53,12 @@ TimedeltaIndex, ) from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin + +_DEPRECATED_FREQ_ALIASES = { + "H": "h", + "T": "min", + "S": "s", +} # -------------------------------------------------------------------- # Offset related functions @@ -600,6 +606,21 @@ def _is_weekly(rule: str) -> bool: return rule == "W" or rule.startswith("W-") +def to_offset(freq): + try: + return _to_offset(freq) + except Exception as err: + if isinstance(freq, str) and freq in _DEPRECATED_FREQ_ALIASES: + suggestion = _DEPRECATED_FREQ_ALIASES[freq] + raise ValueError( + f"Invalid frequency '{freq}'. This alias was deprecated and removed. " + f"Did you mean '{suggestion}'?" + ) from None + raise ValueError( + f"Invalid frequency: {freq}, failed to parse with error message: {err}" + ) from None + + __all__ = [ "Day", "get_period_alias", From 5fe4f9b00d9be0ef20034bf639eeae8af5c69067 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 6 Sep 2025 11:36:36 +0530 Subject: [PATCH 3/4] ERR: Improve error message for deprecated frequency aliases --- pandas/core/series.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 0972cbff8281e..63c9963fb7eac 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6073,9 +6073,7 @@ def eq( Parameters ---------- other : Series or scalar value - The second operand in this operation. Only `np.ndarray`, `list`, `tuple`, - and `Series` are considered "list-like" by pandas. All other types will - be treated as scalar values. + The second operand in this operation. level : int or name Broadcast across a level, matching Index values on the passed MultiIndex level. From 6dc7249eff875000f6356b575688cd10d99184b2 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sun, 7 Sep 2025 07:10:30 +0530 Subject: [PATCH 4/4] ERR: Improve error message for deprecated frequency aliases --- pandas/tseries/frequencies.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index 533f0889c1625..0f3e73f7b1b03 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -613,8 +613,7 @@ def to_offset(freq): if isinstance(freq, str) and freq in _DEPRECATED_FREQ_ALIASES: suggestion = _DEPRECATED_FREQ_ALIASES[freq] raise ValueError( - f"Invalid frequency '{freq}'. This alias was deprecated and removed. " - f"Did you mean '{suggestion}'?" + f"Invalid frequency '{freq}'. Did you mean '{suggestion}'?" ) from None raise ValueError( f"Invalid frequency: {freq}, failed to parse with error message: {err}"