From df90c0c7297aef05d613482363fa01c6f6a05e22 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Wed, 4 Jun 2025 07:17:10 -0400 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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): """