Skip to content

Commit 78ec276

Browse files
authored
DOC: Show constructor arguments for some classes in pd.series.offsets (#61605)
1 parent 7252e9f commit 78ec276

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

doc/source/index.rst.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ programming language.
113113
:titlesonly:
114114

115115
{{ single_doc[:-4] }}
116-
{% elif single_doc and single_doc.count('.') <= 1 %}
116+
{% elif single_doc and ((single_doc.count('.') <= 1) or ('tseries' in single_doc)) -%}
117117
.. autosummary::
118118
:toctree: reference/api/
119119

pandas/_libs/tslibs/offsets.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ class YearOffset(SingleConstructorOffset):
156156

157157
class BYearEnd(YearOffset): ...
158158
class BYearBegin(YearOffset): ...
159-
class YearEnd(YearOffset): ...
159+
160+
class YearEnd(YearOffset):
161+
def __new__(
162+
cls, n: int = ..., normalize: bool = ..., month: int | None = ...
163+
) -> Self: ...
164+
160165
class YearBegin(YearOffset): ...
161166

162167
class QuarterOffset(SingleConstructorOffset):

pandas/_libs/tslibs/offsets.pyx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,14 +2737,31 @@ cdef class BYearBegin(YearOffset):
27372737
_prefix = "BYS"
27382738
_day_opt = "business_start"
27392739

2740+
# The pair of classes `_YearEnd` and `YearEnd` exist because of
2741+
# https://github.com/cython/cython/issues/3873
27402742

2741-
cdef class YearEnd(YearOffset):
2743+
cdef class _YearEnd(YearOffset):
2744+
_default_month = 12
2745+
_prefix = "YE"
2746+
_day_opt = "end"
2747+
2748+
cdef readonly:
2749+
int _period_dtype_code
2750+
2751+
def __init__(self, n=1, normalize=False, month=None):
2752+
# Because YearEnd can be the freq for a Period, define its
2753+
# _period_dtype_code at construction for performance
2754+
YearOffset.__init__(self, n, normalize, month)
2755+
self._period_dtype_code = PeriodDtypeCode.A + self.month % 12
2756+
2757+
2758+
class YearEnd(_YearEnd):
27422759
"""
27432760
DateOffset increments between calendar year end dates.
27442761
27452762
YearEnd goes to the next date which is the end of the year.
27462763
2747-
Attributes
2764+
Parameters
27482765
----------
27492766
n : int, default 1
27502767
The number of years represented.
@@ -2778,18 +2795,8 @@ cdef class YearEnd(YearOffset):
27782795
Timestamp('2022-12-31 00:00:00')
27792796
"""
27802797

2781-
_default_month = 12
2782-
_prefix = "YE"
2783-
_day_opt = "end"
2784-
2785-
cdef readonly:
2786-
int _period_dtype_code
2787-
2788-
def __init__(self, n=1, normalize=False, month=None):
2789-
# Because YearEnd can be the freq for a Period, define its
2790-
# _period_dtype_code at construction for performance
2791-
YearOffset.__init__(self, n, normalize, month)
2792-
self._period_dtype_code = PeriodDtypeCode.A + self.month % 12
2798+
def __new__(cls, n=1, normalize=False, month=None):
2799+
return _YearEnd.__new__(cls, n, normalize, month)
27932800

27942801

27952802
cdef class YearBegin(YearOffset):
@@ -5188,8 +5195,8 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str:
51885195
warnings.warn(
51895196
f"\'{name}\' is deprecated and will be removed "
51905197
f"in a future version, please use "
5191-
f"\'{c_PERIOD_AND_OFFSET_DEPR_FREQSTR.get(name)}\'"
5192-
f" instead.",
5198+
f"\'{c_PERIOD_AND_OFFSET_DEPR_FREQSTR.get(name)}\' "
5199+
f"instead.",
51935200
FutureWarning,
51945201
stacklevel=find_stack_level(),
51955202
)
@@ -5202,8 +5209,8 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str:
52025209
warnings.warn(
52035210
f"\'{name}\' is deprecated and will be removed "
52045211
f"in a future version, please use "
5205-
f"\'{_name}\'"
5206-
f" instead.",
5212+
f"\'{_name}\' "
5213+
f"instead.",
52075214
FutureWarning,
52085215
stacklevel=find_stack_level(),
52095216
)

0 commit comments

Comments
 (0)