@@ -3,8 +3,7 @@ import operator
3
3
4
4
from cpython cimport (
5
5
PyObject_RichCompareBool,
6
- Py_EQ, Py_NE,
7
- )
6
+ Py_EQ, Py_NE)
8
7
9
8
from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
10
9
NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA)
@@ -19,8 +18,11 @@ from pandas import compat
19
18
from pandas.compat import PY2
20
19
21
20
cimport cython
21
+ # this is _libs.src.datetime, not python stdlib
22
22
from datetime cimport *
23
+
23
24
cimport util, lib
25
+
24
26
from lib cimport is_null_datetimelike, is_period
25
27
from pandas._libs import tslib, lib
26
28
from pandas._libs.tslib import (Timedelta, Timestamp, iNaT,
@@ -683,13 +685,17 @@ class IncompatibleFrequency(ValueError):
683
685
684
686
cdef class _Period(object ):
685
687
686
- cdef public :
688
+ cdef readonly :
687
689
int64_t ordinal
688
690
object freq
689
691
690
692
_comparables = [' name' , ' freqstr' ]
691
693
_typ = ' period'
692
694
695
+ def __cinit__ (self , ordinal , freq ):
696
+ self .ordinal = ordinal
697
+ self .freq = freq
698
+
693
699
@classmethod
694
700
def _maybe_convert_freq (cls , object freq ):
695
701
@@ -713,9 +719,8 @@ cdef class _Period(object):
713
719
if ordinal == iNaT:
714
720
return NaT
715
721
else :
716
- self = _Period.__new__ (cls )
717
- self .ordinal = ordinal
718
- self .freq = cls ._maybe_convert_freq(freq)
722
+ freq = cls ._maybe_convert_freq(freq)
723
+ self = _Period.__new__ (cls , ordinal, freq)
719
724
return self
720
725
721
726
def __richcmp__ (self , other , op ):
@@ -767,7 +772,7 @@ cdef class _Period(object):
767
772
def __add__ (self , other ):
768
773
if isinstance (self , Period):
769
774
if isinstance (other, (timedelta, np.timedelta64,
770
- offsets.Tick, offsets. DateOffset,
775
+ offsets.DateOffset,
771
776
Timedelta)):
772
777
return self ._add_delta(other)
773
778
elif other is NaT:
@@ -785,7 +790,7 @@ cdef class _Period(object):
785
790
def __sub__ (self , other ):
786
791
if isinstance (self , Period):
787
792
if isinstance (other, (timedelta, np.timedelta64,
788
- offsets.Tick, offsets. DateOffset,
793
+ offsets.DateOffset,
789
794
Timedelta)):
790
795
neg_other = - other
791
796
return self + neg_other
0 commit comments