@@ -2,15 +2,18 @@ from datetime import datetime, date, timedelta
2
2
import operator
3
3
import numpy as np
4
4
5
+ cdef extern from " datetime_helper.h" :
6
+ double total_seconds(object )
7
+
5
8
from pandas import compat
6
- from pandas.core import common as com
7
- from pandas.core.base import PandasObject
8
9
9
10
from pandas.tseries import frequencies
10
11
from pandas.tseries.frequencies import get_freq_code as _gfc
11
12
from pandas.tseries import offsets
12
13
from pandas.tseries.tools import parse_time_string
13
14
15
+ cimport lib
16
+ import lib
14
17
from pandas import tslib
15
18
from tslib import Timedelta, Timestamp
16
19
@@ -26,7 +29,7 @@ def _period_field_accessor(name, alias):
26
29
return property(f)
27
30
28
31
29
- class Period (PandasObject ):
32
+ class Period (object ):
30
33
"""
31
34
Represents an period of time
32
35
@@ -74,7 +77,7 @@ class Period(PandasObject):
74
77
raise ValueError ((" Only value or ordinal but not both should be "
75
78
" given but not both" ))
76
79
elif ordinal is not None :
77
- if not com .is_integer(ordinal):
80
+ if not lib .is_integer(ordinal):
78
81
raise ValueError (" Ordinal must be an integer" )
79
82
if freq is None :
80
83
raise ValueError (' Must supply freq for ordinal value' )
@@ -96,14 +99,14 @@ class Period(PandasObject):
96
99
converted = other.asfreq(freq)
97
100
self .ordinal = converted.ordinal
98
101
99
- elif com.is_null_datelike_scalar (value) or value in tslib._nat_strings:
102
+ elif lib.is_null_datetimelike (value) or value in tslib._nat_strings:
100
103
self .ordinal = tslib.iNaT
101
104
if freq is None :
102
105
raise ValueError (" If value is NaT, freq cannot be None "
103
106
" because it cannot be inferred" )
104
107
105
- elif isinstance (value, compat.string_types) or com .is_integer(value):
106
- if com .is_integer(value):
108
+ elif isinstance (value, compat.string_types) or lib .is_integer(value):
109
+ if lib .is_integer(value):
107
110
value = str (value)
108
111
value = value.upper()
109
112
@@ -184,7 +187,7 @@ class Period(PandasObject):
184
187
if isinstance (other, (timedelta, np.timedelta64,
185
188
offsets.Tick, offsets.DateOffset, Timedelta)):
186
189
return self ._add_delta(other)
187
- elif com .is_integer(other):
190
+ elif lib .is_integer(other):
188
191
if self .ordinal == tslib.iNaT:
189
192
ordinal = self .ordinal
190
193
else :
@@ -198,7 +201,7 @@ class Period(PandasObject):
198
201
offsets.Tick, offsets.DateOffset, Timedelta)):
199
202
neg_other = - other
200
203
return self + neg_other
201
- elif com .is_integer(other):
204
+ elif lib .is_integer(other):
202
205
if self .ordinal == tslib.iNaT:
203
206
ordinal = self .ordinal
204
207
else :
@@ -320,15 +323,15 @@ class Period(PandasObject):
320
323
def now (cls , freq = None ):
321
324
return Period(datetime.now(), freq = freq)
322
325
326
+ # HACK IT UP AND YOU BETTER FIX IT SOON
327
+ def __str__ (self ):
328
+ return self .__unicode__ ()
329
+
323
330
def __repr__ (self ):
324
331
base, mult = _gfc(self .freq)
325
332
formatted = tslib.period_format(self .ordinal, base)
326
333
freqstr = frequencies._reverse_period_code_map[base]
327
334
328
- if not compat.PY3:
329
- encoding = com.get_option(" display.encoding" )
330
- formatted = formatted.encode(encoding)
331
-
332
335
return " Period('%s ', '%s ')" % (formatted, freqstr)
333
336
334
337
def __unicode__ (self ):
0 commit comments