File tree 1 file changed +18
-1
lines changed
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 22
22
is_datetime64_dtype ,
23
23
is_timedelta64_dtype ,
24
24
is_datetime64tz_dtype ,
25
+ is_period_arraylike ,
25
26
is_list_like ,
26
27
is_dict_like ,
27
28
is_re_compilable ,
@@ -1031,14 +1032,30 @@ def __neg__(self):
1031
1032
arr = operator .inv (values )
1032
1033
elif (is_numeric_dtype (values ) or is_timedelta64_dtype (values )):
1033
1034
arr = operator .neg (values )
1035
+ elif is_period_arraylike (values ):
1036
+ # An incredibly terrible workaround that should be replaced
1037
+ # with real logic for handling time period arithmetic
1038
+ if isinstance (self , ABCSeries ):
1039
+ freq = self .dt .freq
1040
+ year = min (self .dt .year )
1041
+ elif isinstance (self , ABCDataFrame ):
1042
+ freqs = set ([self [col ].dt .freq for col in self ])
1043
+ if len (freqs ) > 1 :
1044
+ raise ("Unary negative requires Period objects have "
1045
+ "same frequency, not {}" .format (freqs ))
1046
+ else :
1047
+ freq = freqs .pop ()
1048
+ year = min (min ([self [col ].dt .year for col in self ]))
1049
+ unit = Period (value = year , freq = freq )
1050
+ arr = unit - self - 1
1034
1051
else :
1035
1052
raise TypeError ("Unary negative expects numeric dtype, not {}"
1036
1053
.format (values .dtype ))
1037
1054
return self .__array_wrap__ (arr )
1038
1055
1039
1056
def __pos__ (self ):
1040
1057
values = com ._values_from_object (self )
1041
- if is_bool_dtype (values ):
1058
+ if ( is_bool_dtype (values ) or is_period_arraylike ( values ) ):
1042
1059
arr = values
1043
1060
elif (is_numeric_dtype (values ) or is_timedelta64_dtype (values )):
1044
1061
arr = operator .pos (values )
You can’t perform that action at this time.
0 commit comments