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 16 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
2 changes: 1 addition & 1 deletion doc/source/index.rst.template
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
7 changes: 6 additions & 1 deletion pandas/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
41 changes: 23 additions & 18 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2681,13 +2681,28 @@ 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


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.
Expand Down Expand Up @@ -2721,18 +2736,8 @@ 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, n=1, normalize=False, month=None):
return _YearEnd.__new__(cls, n, normalize, month)


cdef class YearBegin(YearOffset):
Expand Down Expand Up @@ -5131,8 +5136,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.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dr-Irv this and the following change have for some time caused pre-commit to fail for me locally.

great that this is being fixed here. Thanks.

Any idea why CI hasn't picked this up before now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I was surprised as well.

FutureWarning,
stacklevel=find_stack_level(),
)
Expand All @@ -5145,8 +5150,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