From df90c0c7297aef05d613482363fa01c6f6a05e22 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Wed, 4 Jun 2025 07:17:10 -0400 Subject: [PATCH 01/13] okexcept in enhancingperf.rst --- doc/source/user_guide/enhancingperf.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/user_guide/enhancingperf.rst b/doc/source/user_guide/enhancingperf.rst index 647b0f760f4d4..537e9f4d9e1f9 100644 --- a/doc/source/user_guide/enhancingperf.rst +++ b/doc/source/user_guide/enhancingperf.rst @@ -81,6 +81,7 @@ Let's take a look and see where the time is spent during this operation using the `prun ipython magic function `__: .. ipython:: python + :okexcept: # most time consuming 4 calls %prun -l 4 df.apply(lambda x: integrate_f(x["a"], x["b"], x["N"]), axis=1) # noqa E999 @@ -163,6 +164,7 @@ the index and the series (three times for each row). These Python function calls can be improved by passing an ``np.ndarray``. .. ipython:: python + :okexcept: %prun -l 4 df.apply(lambda x: integrate_f_typed(x["a"], x["b"], x["N"]), axis=1) @@ -217,6 +219,7 @@ The majority of the time is now spent in ``apply_integrate_f``. Disabling Cython and ``wraparound`` checks can yield more performance. .. ipython:: python + :okexcept: %prun -l 4 apply_integrate_f(df["a"].to_numpy(), df["b"].to_numpy(), df["N"].to_numpy()) From 53d68dd5272f20f66fad0a6b816f0a95f17fb0ce Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 7 Jun 2025 15:25:36 -0400 Subject: [PATCH 02/13] trials to get the docs right - rst --- doc/_templates/autosummary/class.rst | 2 +- doc/source/conf.py | 2 +- doc/source/reference/offset_frequency.rst | 2 +- doc/source/user_guide/enhancingperf.rst | 2 ++ pandas/_libs/tslibs/offsets.pyx | 19 +++++++++++++++---- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/doc/_templates/autosummary/class.rst b/doc/_templates/autosummary/class.rst index 79c2e37b0192f..b7a3077a0cfa6 100644 --- a/doc/_templates/autosummary/class.rst +++ b/doc/_templates/autosummary/class.rst @@ -8,7 +8,7 @@ {% block attributes %} {% if attributes %} - .. rubric:: {{ _('Attributes') }} + .. rubric:: {{ _('Axttributes') }} .. autosummary:: {% for item in attributes %} diff --git a/doc/source/conf.py b/doc/source/conf.py index 677ee6274b093..f884b4703e3b0 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -724,7 +724,7 @@ def process_class_docstrings(app, what, name, obj, options, lines) -> None: joined = "\n".join(lines) templates = [ - """.. rubric:: Attributes + """.. rubric:: Ayttributes .. autosummary:: :toctree: diff --git a/doc/source/reference/offset_frequency.rst b/doc/source/reference/offset_frequency.rst index 5876e005574fd..f0f2a244e0ea2 100644 --- a/doc/source/reference/offset_frequency.rst +++ b/doc/source/reference/offset_frequency.rst @@ -1177,7 +1177,7 @@ Tick Tick -Properties +Pxroperties ~~~~~~~~~~ .. autosummary:: :toctree: api/ diff --git a/doc/source/user_guide/enhancingperf.rst b/doc/source/user_guide/enhancingperf.rst index 537e9f4d9e1f9..dbd52911674f3 100644 --- a/doc/source/user_guide/enhancingperf.rst +++ b/doc/source/user_guide/enhancingperf.rst @@ -205,6 +205,7 @@ Since ``apply_integrate_f`` is typed to accept an ``np.ndarray``, :meth:`Series. calls are needed to utilize this function. .. ipython:: python + :okexcept: %timeit apply_integrate_f(df["a"].to_numpy(), df["b"].to_numpy(), df["N"].to_numpy()) @@ -255,6 +256,7 @@ and ``wraparound`` checks can yield more performance. ...: .. ipython:: python + :okexcept: %timeit apply_integrate_f_wrap(df["a"].to_numpy(), df["b"].to_numpy(), df["N"].to_numpy()) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index a16964435ef50..ea48249193397 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1005,6 +1005,9 @@ cdef class SingleConstructorOffset(BaseOffset): # Tick Offsets cdef class Tick(SingleConstructorOffset): + """ + Represents ticks + """ _adjust_dst = False _prefix = "undefined" _attributes = tuple(["n", "normalize"]) @@ -1879,6 +1882,14 @@ cdef class BusinessDay(BusinessMixin): self._offset = state.pop("offset") self._cache = state.pop("_cache", {}) + def __init__(self, n=1, normalize=False, offset=timedelta(0)): + """ + __init__(self, n=1, normalize=False, offset=timedelta(0)) + + This defines init + """ + super().__init__(n, normalize, offset) + def _offset_str(self) -> str: def get_str(td): off_str = "" @@ -5108,8 +5119,8 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str: warnings.warn( f"\'{name}\' is deprecated and will be removed " f"in a future version, please use " - f"\'{c_PERIOD_AND_OFFSET_DEPR_FREQSTR.get(name)}\'" - f" instead.", + f"\'{c_PERIOD_AND_OFFSET_DEPR_FREQSTR.get(name)}\' " + f"instead.", FutureWarning, stacklevel=find_stack_level(), ) @@ -5122,8 +5133,8 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str: warnings.warn( f"\'{name}\' is deprecated and will be removed " f"in a future version, please use " - f"\'{_name}\'" - f" instead.", + f"\'{_name}\' " + f"instead.", FutureWarning, stacklevel=find_stack_level(), ) From 6757399af0aab82e259f4c6eb6f241b9b7d0da67 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 7 Jun 2025 20:31:08 -0400 Subject: [PATCH 03/13] add embedsignature to offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index ea48249193397..0abeff0563a6b 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1,3 +1,5 @@ +# cython: embedsignature=True + import re import time import warnings @@ -1180,6 +1182,11 @@ cdef class Day(Tick): """ Offset ``n`` days. + Parameters + ---------- + n : int + Number of multiples of the frequency. + Attributes ---------- n : int, default 1 From bbdf86972e79aed87f4b525291082e3f00f0bbae Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 7 Jun 2025 20:36:21 -0400 Subject: [PATCH 04/13] revert some experiments --- doc/_templates/autosummary/class.rst | 2 +- doc/source/conf.py | 2 +- doc/source/reference/offset_frequency.rst | 2 +- pandas/_libs/tslibs/offsets.pyx | 11 +++-------- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/doc/_templates/autosummary/class.rst b/doc/_templates/autosummary/class.rst index b7a3077a0cfa6..79c2e37b0192f 100644 --- a/doc/_templates/autosummary/class.rst +++ b/doc/_templates/autosummary/class.rst @@ -8,7 +8,7 @@ {% block attributes %} {% if attributes %} - .. rubric:: {{ _('Axttributes') }} + .. rubric:: {{ _('Attributes') }} .. autosummary:: {% for item in attributes %} diff --git a/doc/source/conf.py b/doc/source/conf.py index f884b4703e3b0..677ee6274b093 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -724,7 +724,7 @@ def process_class_docstrings(app, what, name, obj, options, lines) -> None: joined = "\n".join(lines) templates = [ - """.. rubric:: Ayttributes + """.. rubric:: Attributes .. autosummary:: :toctree: diff --git a/doc/source/reference/offset_frequency.rst b/doc/source/reference/offset_frequency.rst index f0f2a244e0ea2..5876e005574fd 100644 --- a/doc/source/reference/offset_frequency.rst +++ b/doc/source/reference/offset_frequency.rst @@ -1177,7 +1177,7 @@ Tick Tick -Pxroperties +Properties ~~~~~~~~~~ .. autosummary:: :toctree: api/ diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 0abeff0563a6b..0de0859f782ea 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1187,6 +1187,9 @@ cdef class Day(Tick): n : int Number of multiples of the frequency. + normalize: bool + Must be `False` + Attributes ---------- n : int, default 1 @@ -1889,14 +1892,6 @@ cdef class BusinessDay(BusinessMixin): self._offset = state.pop("offset") self._cache = state.pop("_cache", {}) - def __init__(self, n=1, normalize=False, offset=timedelta(0)): - """ - __init__(self, n=1, normalize=False, offset=timedelta(0)) - - This defines init - """ - super().__init__(n, normalize, offset) - def _offset_str(self) -> str: def get_str(td): off_str = "" From 6f5f1bab6d9bf8d4dab843af88715d7d6d7423be Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 7 Jun 2025 21:54:13 -0400 Subject: [PATCH 05/13] define __init__ for Day. remove Tick test doc --- pandas/_libs/tslibs/offsets.pyx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 0de0859f782ea..2a7e17a9a02f3 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1007,9 +1007,6 @@ cdef class SingleConstructorOffset(BaseOffset): # Tick Offsets cdef class Tick(SingleConstructorOffset): - """ - Represents ticks - """ _adjust_dst = False _prefix = "undefined" _attributes = tuple(["n", "normalize"]) @@ -1185,10 +1182,7 @@ cdef class Day(Tick): Parameters ---------- n : int - Number of multiples of the frequency. - - normalize: bool - Must be `False` + Number of multiples of the frequency (default 1). Attributes ---------- @@ -1221,6 +1215,9 @@ cdef class Day(Tick): _period_dtype_code = PeriodDtypeCode.D _creso = NPY_DATETIMEUNIT.NPY_FR_D + def __init__(self, n=1, normalize=False): + super().__init__(n, normalize) + print("in Day init") cdef class Hour(Tick): """ From 3914cda88dca83f7172d69a07d36fd1e2ce50c65 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 7 Jun 2025 22:16:59 -0400 Subject: [PATCH 06/13] remove print --- pandas/_libs/tslibs/offsets.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 2a7e17a9a02f3..21332324af552 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1217,7 +1217,6 @@ cdef class Day(Tick): def __init__(self, n=1, normalize=False): super().__init__(n, normalize) - print("in Day init") cdef class Hour(Tick): """ From 841ddc7b854e40a4d716ec149269e06e16a60434 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 22 Jun 2025 00:51:35 -0400 Subject: [PATCH 07/13] WIP: fix conf for Windows. Experiment with YearEnd --- doc/source/conf.py | 2 ++ pandas/_libs/tslibs/offsets.pyx | 40 ++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 677ee6274b093..f222a228531ff 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -114,6 +114,8 @@ ): exclude_patterns.append(rel_fname) elif single_doc and rel_fname != pattern: + if "\\" in rel_fname: + rel_fname = rel_fname.replace("\\", "/") exclude_patterns.append(rel_fname) with open(os.path.join(source_path, "index.rst.template"), encoding="utf-8") as f: diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 9ce0ded9c7589..3423b8fcc9078 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1,5 +1,3 @@ -# cython: embedsignature=True - import re import time import warnings @@ -79,6 +77,7 @@ from pandas._libs.tslibs.np_datetime cimport ( pandas_datetime_to_datetimestruct, pydate_to_dtstruct, ) +from pandas.util._decorators import set_module import_pandas_datetime() @@ -622,6 +621,7 @@ cdef class BaseOffset: @cache_readonly def freqstr(self) -> str: """ + Return a string representing the frequency. See Also @@ -648,6 +648,7 @@ cdef class BaseOffset: >>> pd.offsets.Nano(-3).freqstr '-3ns' + """ try: code = self.rule_code @@ -2690,13 +2691,29 @@ cdef class BYearBegin(YearOffset): _day_opt = "business_start" -cdef class YearEnd(YearOffset): +cdef class _YearEnd(YearOffset): + _default_month = 12 + _prefix = "YE" + _day_opt = "end" + + cdef readonly: + int _period_dtype_code + + def __init__(self, n=1, normalize=False, month=None): + # Because YearEnd can be the freq for a Period, define its + # _period_dtype_code at construction for performance + YearOffset.__init__(self, n, normalize, month) + self._period_dtype_code = PeriodDtypeCode.A + self.month % 12 + + +@set_module("pandas.tseries.offsets") +class YearEnd(_YearEnd): """ DateOffset increments between calendar year end dates. YearEnd goes to the next date which is the end of the year. - Attributes + Parameters ---------- n : int, default 1 The number of years represented. @@ -2730,18 +2747,9 @@ cdef class YearEnd(YearOffset): Timestamp('2022-12-31 00:00:00') """ - _default_month = 12 - _prefix = "YE" - _day_opt = "end" - - cdef readonly: - int _period_dtype_code - - def __init__(self, n=1, normalize=False, month=None): - # Because YearEnd can be the freq for a Period, define its - # _period_dtype_code at construction for performance - YearOffset.__init__(self, n, normalize, month) - self._period_dtype_code = PeriodDtypeCode.A + self.month % 12 + def __new__(cls, fuck=None, normalize=False, month=None): + # this is a comment + return _YearEnd.__new__(cls, fuck, normalize, month) cdef class YearBegin(YearOffset): From 5783fd2f59cb942c2c89beff069d51f54086093c Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 22 Jun 2025 15:58:23 -0400 Subject: [PATCH 08/13] fix template and remove okexcept --- doc/source/index.rst.template | 2 +- doc/source/user_guide/enhancingperf.rst | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/doc/source/index.rst.template b/doc/source/index.rst.template index 8a72df0661fe4..40789d8def53d 100644 --- a/doc/source/index.rst.template +++ b/doc/source/index.rst.template @@ -113,7 +113,7 @@ programming language. :titlesonly: {{ single_doc[:-4] }} -{% elif single_doc and single_doc.count('.') <= 1 %} +{% elif single_doc and ((single_doc.count('.') <= 1) or ('tseries' in single_doc)) -%} .. autosummary:: :toctree: reference/api/ diff --git a/doc/source/user_guide/enhancingperf.rst b/doc/source/user_guide/enhancingperf.rst index 2921bf030bf2c..9d6179ef85bb3 100644 --- a/doc/source/user_guide/enhancingperf.rst +++ b/doc/source/user_guide/enhancingperf.rst @@ -81,7 +81,6 @@ Let's take a look and see where the time is spent during this operation using the `prun ipython magic function `__: .. ipython:: python - :okexcept: # most time consuming 4 calls %prun -l 4 df.apply(lambda x: integrate_f(x['a'], x['b'], x['N']), axis=1) @@ -164,7 +163,6 @@ the index and the series (three times for each row). These Python function calls can be improved by passing an ``np.ndarray``. .. ipython:: python - :okexcept: %prun -l 4 df.apply(lambda x: integrate_f_typed(x['a'], x['b'], x['N']), axis=1) @@ -205,7 +203,6 @@ Since ``apply_integrate_f`` is typed to accept an ``np.ndarray``, :meth:`Series. calls are needed to utilize this function. .. ipython:: python - :okexcept: %timeit apply_integrate_f(df['a'].to_numpy(), df['b'].to_numpy(), df['N'].to_numpy()) @@ -220,7 +217,6 @@ The majority of the time is now spent in ``apply_integrate_f``. Disabling Cython and ``wraparound`` checks can yield more performance. .. ipython:: python - :okexcept: %prun -l 4 apply_integrate_f(df['a'].to_numpy(), df['b'].to_numpy(), df['N'].to_numpy()) @@ -256,7 +252,6 @@ and ``wraparound`` checks can yield more performance. ...: .. ipython:: python - :okexcept: %timeit apply_integrate_f_wrap(df['a'].to_numpy(), df['b'].to_numpy(), df['N'].to_numpy()) @@ -534,7 +529,6 @@ name in an expression. isn't defined in that context. .. ipython:: python - :okexcept: a, b = 1, 2 pd.eval("@a + b") From 0b07f66b4a0fb328549a0238e8f3550ad66621ce Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 22 Jun 2025 15:59:36 -0400 Subject: [PATCH 09/13] put back an okexcept --- doc/source/user_guide/enhancingperf.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/user_guide/enhancingperf.rst b/doc/source/user_guide/enhancingperf.rst index 9d6179ef85bb3..9c37f317a805e 100644 --- a/doc/source/user_guide/enhancingperf.rst +++ b/doc/source/user_guide/enhancingperf.rst @@ -529,6 +529,7 @@ name in an expression. isn't defined in that context. .. ipython:: python + :okexcept: a, b = 1, 2 pd.eval("@a + b") From 788534a4f2612179c088f6096d53721eb41c0bd0 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 22 Jun 2025 16:23:58 -0400 Subject: [PATCH 10/13] remove set_module and debugging --- pandas/_libs/tslibs/offsets.pyx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 3423b8fcc9078..4c91c6e8851bf 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -77,7 +77,6 @@ from pandas._libs.tslibs.np_datetime cimport ( pandas_datetime_to_datetimestruct, pydate_to_dtstruct, ) -from pandas.util._decorators import set_module import_pandas_datetime() @@ -2706,7 +2705,6 @@ cdef class _YearEnd(YearOffset): self._period_dtype_code = PeriodDtypeCode.A + self.month % 12 -@set_module("pandas.tseries.offsets") class YearEnd(_YearEnd): """ DateOffset increments between calendar year end dates. @@ -2747,9 +2745,8 @@ class YearEnd(_YearEnd): Timestamp('2022-12-31 00:00:00') """ - def __new__(cls, fuck=None, normalize=False, month=None): - # this is a comment - return _YearEnd.__new__(cls, fuck, normalize, month) + def __new__(cls, n=1, normalize=False, month=None): + return _YearEnd.__new__(cls, n, normalize, month) cdef class YearBegin(YearOffset): From 86e670b88902507bb9dcbfc6dfa786319a12c4c7 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 22 Jun 2025 16:26:16 -0400 Subject: [PATCH 11/13] remove additional trials --- pandas/_libs/tslibs/offsets.pyx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 4c91c6e8851bf..7009f722ce6b2 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -620,7 +620,6 @@ cdef class BaseOffset: @cache_readonly def freqstr(self) -> str: """ - Return a string representing the frequency. See Also @@ -647,7 +646,6 @@ cdef class BaseOffset: >>> pd.offsets.Nano(-3).freqstr '-3ns' - """ try: code = self.rule_code @@ -1179,11 +1177,6 @@ cdef class Day(Tick): """ Offset ``n`` days. - Parameters - ---------- - n : int - Number of multiples of the frequency (default 1). - Attributes ---------- n : int, default 1 From 92a8ead5cdb42be0e188ad043df5284899035a10 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 22 Jun 2025 16:27:50 -0400 Subject: [PATCH 12/13] remove init from Day --- pandas/_libs/tslibs/offsets.pyx | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 7009f722ce6b2..9253adef369a5 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1208,8 +1208,6 @@ cdef class Day(Tick): _period_dtype_code = PeriodDtypeCode.D _creso = NPY_DATETIMEUNIT.NPY_FR_D - def __init__(self, n=1, normalize=False): - super().__init__(n, normalize) cdef class Hour(Tick): """ From ddbd31a96a012ff068100d0b16878793d2328571 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 22 Jun 2025 19:14:03 -0400 Subject: [PATCH 13/13] add __new__() for YearEnd in PYI file --- pandas/_libs/tslibs/offsets.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyi b/pandas/_libs/tslibs/offsets.pyi index a71aa42b4f671..94deadae256e6 100644 --- a/pandas/_libs/tslibs/offsets.pyi +++ b/pandas/_libs/tslibs/offsets.pyi @@ -156,7 +156,12 @@ class YearOffset(SingleConstructorOffset): class BYearEnd(YearOffset): ... class BYearBegin(YearOffset): ... -class YearEnd(YearOffset): ... + +class YearEnd(YearOffset): + def __new__( + cls, n: int = ..., normalize: bool = ..., month: int | None = ... + ) -> Self: ... + class YearBegin(YearOffset): ... class QuarterOffset(SingleConstructorOffset):