@@ -612,15 +612,6 @@ cdef ndarray[int64_t] localize_dt64arr_to_period(ndarray[int64_t] stamps,
612
612
return result
613
613
614
614
615
- def _period_field_accessor (name , alias ):
616
- def f (self ):
617
- from pandas.tseries.frequencies import get_freq_code as _gfc
618
- base, mult = _gfc(self .freq)
619
- return get_period_field(alias, self .ordinal, base)
620
- f.__name__ = name
621
- return property(f)
622
-
623
-
624
615
cdef class Period(object ):
625
616
"""
626
617
Represents an period of time
@@ -890,19 +881,50 @@ cdef class Period(object):
890
881
dt64 = period_ordinal_to_dt64(val.ordinal, base)
891
882
return Timestamp(dt64, tz = tz)
892
883
893
- year = _period_field_accessor(' year' , 0 )
894
- month = _period_field_accessor(' month' , 3 )
895
- day = _period_field_accessor(' day' , 4 )
896
- hour = _period_field_accessor(' hour' , 5 )
897
- minute = _period_field_accessor(' minute' , 6 )
898
- second = _period_field_accessor(' second' , 7 )
899
- weekofyear = _period_field_accessor(' week' , 8 )
900
- week = weekofyear
901
- dayofweek = _period_field_accessor(' dayofweek' , 10 )
902
- weekday = dayofweek
903
- dayofyear = _period_field_accessor(' dayofyear' , 9 )
904
- quarter = _period_field_accessor(' quarter' , 2 )
905
- qyear = _period_field_accessor(' qyear' , 1 )
884
+ cdef _field(self , alias):
885
+ from pandas.tseries.frequencies import get_freq_code as _gfc
886
+ base, mult = _gfc(self .freq)
887
+ return get_period_field(alias, self .ordinal, base)
888
+
889
+ property year :
890
+ def __get__ (self ):
891
+ return self ._field(0 )
892
+ property month :
893
+ def __get__ (self ):
894
+ return self ._field(3 )
895
+ property day :
896
+ def __get__ (self ):
897
+ return self ._field(4 )
898
+ property hour :
899
+ def __get__ (self ):
900
+ return self ._field(5 )
901
+ property minute :
902
+ def __get__ (self ):
903
+ return self ._field(6 )
904
+ property second :
905
+ def __get__ (self ):
906
+ return self ._field(7 )
907
+ property weekofyear :
908
+ def __get__ (self ):
909
+ return self ._field(8 )
910
+ property week :
911
+ def __get__ (self ):
912
+ return self .weekofyear
913
+ property dayofweek :
914
+ def __get__ (self ):
915
+ return self ._field(10 )
916
+ property weekday :
917
+ def __get__ (self ):
918
+ return self .dayofweek
919
+ property dayofyear :
920
+ def __get__ (self ):
921
+ return self ._field(9 )
922
+ property quarter :
923
+ def __get__ (self ):
924
+ return self ._field(2 )
925
+ property qyear :
926
+ def __get__ (self ):
927
+ return self ._field(1 )
906
928
907
929
@classmethod
908
930
def now (cls , freq = None ):
0 commit comments