@@ -473,9 +473,6 @@ cdef int DtoQ_yq(int64_t ordinal, asfreq_info *af_info, int *year) nogil:
473
473
int quarter
474
474
475
475
pandas_datetime_to_datetimestruct(ordinal, NPY_FR_D, & dts)
476
- # TODO: Another version of this function used
477
- # date_info_from_days_and_time(&dts, unix_date, 0)
478
- # instead of pandas_datetime_to_datetimestruct; is one more performant?
479
476
if af_info.to_end != 12 :
480
477
dts.month -= af_info.to_end
481
478
if dts.month <= 0 :
@@ -516,7 +513,7 @@ cdef int64_t asfreq_DTtoW(int64_t ordinal, asfreq_info *af_info) nogil:
516
513
# Conversion _from_ BusinessDay Freq
517
514
518
515
cdef int64_t asfreq_BtoDT(int64_t ordinal, asfreq_info * af_info) nogil:
519
- ordinal = ((ordinal + 3 ) // 5 ) * 7 + (ordinal + 3 ) % 5 - 3
516
+ ordinal = ((ordinal + 3 ) // 5 ) * 7 + (ordinal + 3 ) % 5 - 3
520
517
return upsample_daytime(ordinal, af_info)
521
518
522
519
@@ -753,14 +750,7 @@ cdef int64_t get_period_ordinal(npy_datetimestruct *dts, int freq) nogil:
753
750
if fmonth == 0 :
754
751
fmonth = 12
755
752
756
- mdiff = dts.month - fmonth
757
- # TODO: Aren't the next two conditions equivalent to
758
- # unconditional incrementing?
759
- if mdiff < 0 :
760
- mdiff += 12
761
- if dts.month >= fmonth:
762
- mdiff += 12
763
-
753
+ mdiff = dts.month - fmonth + 12
764
754
return (dts.year - 1970 ) * 4 + (mdiff - 1 ) // 3
765
755
766
756
elif freq == FR_MTH:
@@ -804,17 +794,16 @@ cdef int64_t get_period_ordinal(npy_datetimestruct *dts, int freq) nogil:
804
794
delta = (unix_date + 3 ) % 7 + 1
805
795
# return the number of business days in full weeks plus the business
806
796
# days in the last - possible partial - week
807
- if delta <= 5 :
808
- return (5 * weeks) + delta - 4
809
- else :
810
- return (5 * weeks) + (5 + 1 ) - 4
797
+ if delta > 6 :
798
+ # We have a Sunday, which rolls back to the previous Friday,
799
+ # just like Saturday, so decrement delta by 1 to treat as saturday
800
+ delta = 6
801
+ return (5 * weeks) + delta - 4
811
802
812
803
elif freq_group == FR_WK:
813
804
day_adj = freq - FR_WK
814
805
return (unix_date + 3 - day_adj) // 7 + 1
815
806
816
- # raise ValueError
817
-
818
807
819
808
cdef void get_date_info(int64_t ordinal, int freq,
820
809
npy_datetimestruct * dts) nogil:
@@ -983,7 +972,7 @@ cdef inline int month_to_quarter(int month) nogil:
983
972
984
973
@ cython.wraparound (False )
985
974
@ cython.boundscheck (False )
986
- def dt64arr_to_periodarr (int64_t[:] dtarr , int freq , tz = None ):
975
+ def dt64arr_to_periodarr (const int64_t[:] dtarr , int freq , tz = None ):
987
976
"""
988
977
Convert array of datetime64 values (passed in as 'i8' dtype) to a set of
989
978
periods corresponding to desired frequency, per period convention.
@@ -1383,7 +1372,7 @@ cdef int pdays_in_month(int64_t ordinal, int freq):
1383
1372
1384
1373
@ cython.wraparound (False )
1385
1374
@ cython.boundscheck (False )
1386
- def get_period_field_arr (int code , int64_t[:] arr , int freq ):
1375
+ def get_period_field_arr (int code , const int64_t[:] arr , int freq ):
1387
1376
cdef:
1388
1377
Py_ssize_t i, sz
1389
1378
int64_t[:] out
@@ -1496,7 +1485,7 @@ def extract_freq(ndarray[object] values):
1496
1485
1497
1486
@ cython.wraparound (False )
1498
1487
@ cython.boundscheck (False )
1499
- cdef int64_t[:] localize_dt64arr_to_period(int64_t[:] stamps,
1488
+ cdef int64_t[:] localize_dt64arr_to_period(const int64_t[:] stamps,
1500
1489
int freq, object tz):
1501
1490
cdef:
1502
1491
Py_ssize_t n = len (stamps)
@@ -1584,7 +1573,7 @@ cdef class _Period:
1584
1573
return freq
1585
1574
1586
1575
@classmethod
1587
- def _from_ordinal (cls , ordinal , freq ):
1576
+ def _from_ordinal (cls , ordinal: int , freq ) -> "Period" :
1588
1577
"""
1589
1578
Fast creation from an ordinal and freq that are already validated!
1590
1579
"""
@@ -1704,7 +1693,7 @@ cdef class _Period:
1704
1693
else :
1705
1694
return NotImplemented
1706
1695
1707
- def asfreq (self , freq , how = ' E' ):
1696
+ def asfreq (self , freq , how = ' E' ) -> "Period" :
1708
1697
"""
1709
1698
Convert Period to desired frequency , at the start or end of the interval.
1710
1699
@@ -1735,7 +1724,7 @@ cdef class _Period:
1735
1724
return Period(ordinal = ordinal, freq = freq)
1736
1725
1737
1726
@property
1738
- def start_time (self ):
1727
+ def start_time(self ) -> Timestamp :
1739
1728
"""
1740
1729
Get the Timestamp for the start of the period.
1741
1730
@@ -1765,13 +1754,13 @@ cdef class _Period:
1765
1754
return self.to_timestamp(how = ' S' )
1766
1755
1767
1756
@property
1768
- def end_time (self ):
1757
+ def end_time(self ) -> Timestamp :
1769
1758
# freq.n can't be negative or 0
1770
1759
# ordinal = (self + self .freq.n).start_time.value - 1
1771
1760
ordinal = (self + self .freq).start_time.value - 1
1772
1761
return Timestamp(ordinal )
1773
1762
1774
- def to_timestamp (self , freq = None , how = ' start' , tz = None ):
1763
+ def to_timestamp(self , freq = None , how = ' start' , tz = None ) -> Timestamp :
1775
1764
"""
1776
1765
Return the Timestamp representation of the Period.
1777
1766
@@ -1811,17 +1800,17 @@ cdef class _Period:
1811
1800
return Timestamp(dt64 , tz = tz)
1812
1801
1813
1802
@property
1814
- def year (self ):
1803
+ def year(self ) -> int :
1815
1804
base , mult = get_freq_code(self .freq)
1816
1805
return pyear(self.ordinal , base )
1817
1806
1818
1807
@property
1819
- def month (self ):
1808
+ def month(self ) -> int :
1820
1809
base , mult = get_freq_code(self .freq)
1821
1810
return pmonth(self.ordinal , base )
1822
1811
1823
1812
@property
1824
- def day (self ):
1813
+ def day(self ) -> int :
1825
1814
"""
1826
1815
Get day of the month that a Period falls on.
1827
1816
@@ -1844,7 +1833,7 @@ cdef class _Period:
1844
1833
return pday(self.ordinal , base )
1845
1834
1846
1835
@property
1847
- def hour (self ):
1836
+ def hour(self ) -> int :
1848
1837
"""
1849
1838
Get the hour of the day component of the Period.
1850
1839
@@ -1874,7 +1863,7 @@ cdef class _Period:
1874
1863
return phour(self.ordinal , base )
1875
1864
1876
1865
@property
1877
- def minute (self ):
1866
+ def minute(self ) -> int :
1878
1867
"""
1879
1868
Get minute of the hour component of the Period.
1880
1869
@@ -1898,7 +1887,7 @@ cdef class _Period:
1898
1887
return pminute(self.ordinal , base )
1899
1888
1900
1889
@property
1901
- def second (self ):
1890
+ def second(self ) -> int :
1902
1891
"""
1903
1892
Get the second component of the Period.
1904
1893
@@ -1922,12 +1911,12 @@ cdef class _Period:
1922
1911
return psecond(self.ordinal , base )
1923
1912
1924
1913
@property
1925
- def weekofyear (self ):
1914
+ def weekofyear(self ) -> int :
1926
1915
base , mult = get_freq_code(self .freq)
1927
1916
return pweek(self.ordinal , base )
1928
1917
1929
1918
@property
1930
- def week (self ):
1919
+ def week(self ) -> int :
1931
1920
"""
1932
1921
Get the week of the year on the given Period.
1933
1922
@@ -1957,7 +1946,7 @@ cdef class _Period:
1957
1946
return self.weekofyear
1958
1947
1959
1948
@property
1960
- def dayofweek (self ):
1949
+ def dayofweek(self ) -> int :
1961
1950
"""
1962
1951
Day of the week the period lies in , with Monday = 0 and Sunday= 6.
1963
1952
@@ -2008,7 +1997,7 @@ cdef class _Period:
2008
1997
return pweekday(self.ordinal , base )
2009
1998
2010
1999
@property
2011
- def weekday (self ):
2000
+ def weekday(self ) -> int :
2012
2001
"""
2013
2002
Day of the week the period lies in , with Monday = 0 and Sunday= 6.
2014
2003
@@ -2061,7 +2050,7 @@ cdef class _Period:
2061
2050
return self.dayofweek
2062
2051
2063
2052
@property
2064
- def dayofyear (self ):
2053
+ def dayofyear(self ) -> int :
2065
2054
"""
2066
2055
Return the day of the year.
2067
2056
@@ -2096,12 +2085,12 @@ cdef class _Period:
2096
2085
return pday_of_year(self.ordinal , base )
2097
2086
2098
2087
@property
2099
- def quarter (self ):
2088
+ def quarter(self ) -> int :
2100
2089
base , mult = get_freq_code(self .freq)
2101
2090
return pquarter(self.ordinal , base )
2102
2091
2103
2092
@property
2104
- def qyear (self ):
2093
+ def qyear(self ) -> int :
2105
2094
"""
2106
2095
Fiscal year the Period lies in according to its starting-quarter.
2107
2096
@@ -2145,7 +2134,7 @@ cdef class _Period:
2145
2134
return pqyear(self.ordinal , base )
2146
2135
2147
2136
@property
2148
- def days_in_month (self ):
2137
+ def days_in_month(self ) -> int :
2149
2138
"""
2150
2139
Get the total number of days in the month that this period falls on.
2151
2140
@@ -2179,7 +2168,7 @@ cdef class _Period:
2179
2168
return pdays_in_month(self.ordinal , base )
2180
2169
2181
2170
@property
2182
- def daysinmonth (self ):
2171
+ def daysinmonth(self ) -> int :
2183
2172
"""
2184
2173
Get the total number of days of the month that the Period falls in.
2185
2174
@@ -2209,7 +2198,7 @@ cdef class _Period:
2209
2198
return Period(datetime.now(), freq = freq)
2210
2199
2211
2200
@property
2212
- def freqstr (self ):
2201
+ def freqstr (self ) -> str :
2213
2202
return self.freq.freqstr
2214
2203
2215
2204
def __repr__(self ) -> str:
0 commit comments