Skip to content

DOC: Show constructor arguments for some classes in pd.series.offsets #61605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/source/user_guide/enhancingperf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-prun>`__:

.. 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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -203,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())

Expand All @@ -217,6 +220,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())

Expand Down Expand Up @@ -252,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())

Expand Down
17 changes: 13 additions & 4 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# cython: embedsignature=True

import re
import time
import warnings
Expand Down Expand Up @@ -1177,6 +1179,11 @@ cdef class Day(Tick):
"""
Offset ``n`` days.

Parameters
----------
n : int
Number of multiples of the frequency (default 1).

Attributes
----------
n : int, default 1
Expand Down Expand Up @@ -1208,6 +1215,8 @@ 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):
"""
Expand Down Expand Up @@ -5108,8 +5117,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(),
)
Expand All @@ -5122,8 +5131,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(),
)
Expand Down
Loading