Skip to content

Commit 60915b4

Browse files
API: Removed PeriodDtype.dtype_code from public API (#34796)
1 parent 59137c9 commit 60915b4

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

pandas/_libs/tslibs/dtypes.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ cdef enum PeriodDtypeCode:
7373

7474
cdef class PeriodDtypeBase:
7575
cdef readonly:
76-
PeriodDtypeCode dtype_code
76+
PeriodDtypeCode _dtype_code

pandas/_libs/tslibs/dtypes.pyx

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ cdef class PeriodDtypeBase:
88
describing a PeriodDtype in an integer code.
99
"""
1010
# cdef readonly:
11-
# PeriodDtypeCode dtype_code
11+
# PeriodDtypeCode _dtype_code
1212

1313
def __cinit__(self, PeriodDtypeCode code):
14-
self.dtype_code = code
14+
self._dtype_code = code
1515

1616
def __eq__(self, other):
1717
if not isinstance(other, PeriodDtypeBase):
1818
return False
1919
if not isinstance(self, PeriodDtypeBase):
2020
# cython semantics, this is a reversed op
2121
return False
22-
return self.dtype_code == other.dtype_code
22+
return self._dtype_code == other._dtype_code
2323

2424
@property
2525
def freq_group(self) -> int:
2626
# See also: libperiod.get_freq_group
27-
return (self.dtype_code // 1000) * 1000
27+
return (self._dtype_code // 1000) * 1000
2828

2929
@property
3030
def date_offset(self):
@@ -35,8 +35,8 @@ cdef class PeriodDtypeBase:
3535
"""
3636
from .offsets import to_offset
3737

38-
freqstr = _reverse_period_code_map.get(self.dtype_code)
39-
# equiv: freqstr = libfrequencies.get_freq_str(self.dtype_code)
38+
freqstr = _reverse_period_code_map.get(self._dtype_code)
39+
# equiv: freqstr = libfrequencies.get_freq_str(self._dtype_code)
4040

4141
return to_offset(freqstr)
4242

pandas/_libs/tslibs/period.pyx

+17-17
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ cdef class _Period:
16451645
"""
16461646
freq = self._maybe_convert_freq(freq)
16471647
how = validate_end_alias(how)
1648-
base1 = self._dtype.dtype_code
1648+
base1 = self._dtype._dtype_code
16491649
base2 = freq_to_dtype_code(freq)
16501650

16511651
# self.n can't be negative or 0
@@ -1734,7 +1734,7 @@ cdef class _Period:
17341734
return endpoint - Timedelta(1, 'ns')
17351735

17361736
if freq is None:
1737-
base = self._dtype.dtype_code
1737+
base = self._dtype._dtype_code
17381738
freq = get_to_timestamp_base(base)
17391739
base = freq
17401740
else:
@@ -1748,12 +1748,12 @@ cdef class _Period:
17481748

17491749
@property
17501750
def year(self) -> int:
1751-
base = self._dtype.dtype_code
1751+
base = self._dtype._dtype_code
17521752
return pyear(self.ordinal, base)
17531753

17541754
@property
17551755
def month(self) -> int:
1756-
base = self._dtype.dtype_code
1756+
base = self._dtype._dtype_code
17571757
return pmonth(self.ordinal, base)
17581758

17591759
@property
@@ -1776,7 +1776,7 @@ cdef class _Period:
17761776
>>> p.day
17771777
11
17781778
"""
1779-
base = self._dtype.dtype_code
1779+
base = self._dtype._dtype_code
17801780
return pday(self.ordinal, base)
17811781

17821782
@property
@@ -1806,7 +1806,7 @@ cdef class _Period:
18061806
>>> p.hour
18071807
0
18081808
"""
1809-
base = self._dtype.dtype_code
1809+
base = self._dtype._dtype_code
18101810
return phour(self.ordinal, base)
18111811

18121812
@property
@@ -1830,7 +1830,7 @@ cdef class _Period:
18301830
>>> p.minute
18311831
3
18321832
"""
1833-
base = self._dtype.dtype_code
1833+
base = self._dtype._dtype_code
18341834
return pminute(self.ordinal, base)
18351835

18361836
@property
@@ -1854,12 +1854,12 @@ cdef class _Period:
18541854
>>> p.second
18551855
12
18561856
"""
1857-
base = self._dtype.dtype_code
1857+
base = self._dtype._dtype_code
18581858
return psecond(self.ordinal, base)
18591859

18601860
@property
18611861
def weekofyear(self) -> int:
1862-
base = self._dtype.dtype_code
1862+
base = self._dtype._dtype_code
18631863
return pweek(self.ordinal, base)
18641864

18651865
@property
@@ -1940,7 +1940,7 @@ cdef class _Period:
19401940
>>> per.end_time.dayofweek
19411941
2
19421942
"""
1943-
base = self._dtype.dtype_code
1943+
base = self._dtype._dtype_code
19441944
return pweekday(self.ordinal, base)
19451945

19461946
@property
@@ -2028,12 +2028,12 @@ cdef class _Period:
20282028
>>> period.dayofyear
20292029
1
20302030
"""
2031-
base = self._dtype.dtype_code
2031+
base = self._dtype._dtype_code
20322032
return pday_of_year(self.ordinal, base)
20332033

20342034
@property
20352035
def quarter(self) -> int:
2036-
base = self._dtype.dtype_code
2036+
base = self._dtype._dtype_code
20372037
return pquarter(self.ordinal, base)
20382038

20392039
@property
@@ -2077,7 +2077,7 @@ cdef class _Period:
20772077
>>> per.year
20782078
2017
20792079
"""
2080-
base = self._dtype.dtype_code
2080+
base = self._dtype._dtype_code
20812081
return pqyear(self.ordinal, base)
20822082

20832083
@property
@@ -2111,7 +2111,7 @@ cdef class _Period:
21112111
>>> p.days_in_month
21122112
29
21132113
"""
2114-
base = self._dtype.dtype_code
2114+
base = self._dtype._dtype_code
21152115
return pdays_in_month(self.ordinal, base)
21162116

21172117
@property
@@ -2149,15 +2149,15 @@ cdef class _Period:
21492149
return self.freq.freqstr
21502150

21512151
def __repr__(self) -> str:
2152-
base = self._dtype.dtype_code
2152+
base = self._dtype._dtype_code
21532153
formatted = period_format(self.ordinal, base)
21542154
return f"Period('{formatted}', '{self.freqstr}')"
21552155

21562156
def __str__(self) -> str:
21572157
"""
21582158
Return a string representation for a particular DataFrame
21592159
"""
2160-
base = self._dtype.dtype_code
2160+
base = self._dtype._dtype_code
21612161
formatted = period_format(self.ordinal, base)
21622162
value = str(formatted)
21632163
return value
@@ -2309,7 +2309,7 @@ cdef class _Period:
23092309
>>> a.strftime('%b. %d, %Y was a %A')
23102310
'Jan. 01, 2001 was a Monday'
23112311
"""
2312-
base = self._dtype.dtype_code
2312+
base = self._dtype._dtype_code
23132313
return period_format(self.ordinal, base, fmt)
23142314

23152315

0 commit comments

Comments
 (0)