42
42
43
43
_np_version = np .version .short_version
44
44
_np_version_under1p6 = LooseVersion (_np_version ) < '1.6'
45
+ _np_version_under1p7 = LooseVersion (_np_version ) < '1.7'
45
46
46
47
_SHOW_WARNINGS = True
47
48
@@ -71,19 +72,30 @@ def na_op(x, y):
71
72
72
73
def wrapper (self , other ):
73
74
from pandas .core .frame import DataFrame
75
+ wrap_results = lambda x : x
76
+
77
+ lvalues , rvalues = self , other
78
+
79
+ if (com .is_datetime64_dtype (self ) and
80
+ com .is_datetime64_dtype (other )):
81
+ lvalues = lvalues .view ('i8' )
82
+ rvalues = rvalues .view ('i8' )
83
+
84
+ wrap_results = lambda rs : rs .astype ('timedelta64[ns]' )
85
+
86
+ if isinstance (rvalues , Series ):
87
+ lvalues = lvalues .values
88
+ rvalues = rvalues .values
89
+
74
90
75
- if isinstance (other , Series ):
76
91
if self .index .equals (other .index ):
77
92
name = _maybe_match_name (self , other )
78
- return Series (na_op (self . values , other . values ),
93
+ return Series (wrap_results ( na_op (lvalues , rvalues ) ),
79
94
index = self .index , name = name )
80
95
81
96
join_idx , lidx , ridx = self .index .join (other .index , how = 'outer' ,
82
97
return_indexers = True )
83
98
84
- lvalues = self .values
85
- rvalues = other .values
86
-
87
99
if lidx is not None :
88
100
lvalues = com .take_1d (lvalues , lidx )
89
101
@@ -98,7 +110,7 @@ def wrapper(self, other):
98
110
return NotImplemented
99
111
else :
100
112
# scalars
101
- return Series (na_op (self .values , other ),
113
+ return Series (na_op (lvalues .values , rvalues ),
102
114
index = self .index , name = self .name )
103
115
return wrapper
104
116
0 commit comments