16
16
_ensure_object )
17
17
18
18
from pandas .types .generic import ABCSeries
19
- from pandas .types .missing import isnull
20
-
21
19
22
20
import pandas .tseries .frequencies as frequencies
23
21
from pandas .tseries .frequencies import get_freq_code as _gfc
40
38
from pandas .util .decorators import Appender , cache_readonly , Substitution
41
39
from pandas .lib import Timedelta
42
40
import pandas .tslib as tslib
43
- import pandas .core .missing as missing
44
41
from pandas .compat import zip , u
45
42
46
43
@@ -87,8 +84,7 @@ def wrapper(self, other):
87
84
88
85
result = getattr (self .values , opname )(other .values )
89
86
90
- mask = (missing .mask_missing (self .values , tslib .iNaT ) |
91
- missing .mask_missing (other .values , tslib .iNaT ))
87
+ mask = self ._isnan | other ._isnan
92
88
if mask .any ():
93
89
result [mask ] = nat_result
94
90
@@ -101,9 +97,8 @@ def wrapper(self, other):
101
97
func = getattr (self .values , opname )
102
98
result = func (other .ordinal )
103
99
104
- mask = self .values == tslib .iNaT
105
- if mask .any ():
106
- result [mask ] = nat_result
100
+ if self .hasnans :
101
+ result [self ._isnan ] = nat_result
107
102
108
103
return result
109
104
return wrapper
@@ -498,8 +493,7 @@ def asfreq(self, freq=None, how='E'):
498
493
new_data = period .period_asfreq_arr (ordinal , base1 , base2 , end )
499
494
500
495
if self .hasnans :
501
- mask = asi8 == tslib .iNaT
502
- new_data [mask ] = tslib .iNaT
496
+ new_data [self ._isnan ] = tslib .iNaT
503
497
504
498
return self ._simple_new (new_data , self .name , freq = freq )
505
499
@@ -637,9 +631,8 @@ def _sub_period(self, other):
637
631
new_data = asi8 - other .ordinal
638
632
639
633
if self .hasnans :
640
- mask = asi8 == tslib .iNaT
641
634
new_data = new_data .astype (np .float64 )
642
- new_data [mask ] = np .nan
635
+ new_data [self . _isnan ] = np .nan
643
636
# result must be Int64Index or Float64Index
644
637
return Index (new_data , name = self .name )
645
638
@@ -892,16 +885,21 @@ def __getitem__(self, key):
892
885
def _format_native_types (self , na_rep = u ('NaT' ), date_format = None ,
893
886
** kwargs ):
894
887
895
- values = np .array (list (self ), dtype = object )
896
- mask = isnull (self .values )
897
- values [mask ] = na_rep
898
- imask = ~ mask
888
+ values = self .asobject .values
899
889
900
890
if date_format :
901
891
formatter = lambda dt : dt .strftime (date_format )
902
892
else :
903
893
formatter = lambda dt : u ('%s' ) % dt
904
- values [imask ] = np .array ([formatter (dt ) for dt in values [imask ]])
894
+
895
+ if self .hasnans :
896
+ mask = self ._isnan
897
+ values [mask ] = na_rep
898
+ imask = ~ mask
899
+ values [imask ] = np .array ([formatter (dt ) for dt
900
+ in values [imask ]])
901
+ else :
902
+ values = np .array ([formatter (dt ) for dt in values ])
905
903
return values
906
904
907
905
def append (self , other ):
0 commit comments