File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -826,10 +826,22 @@ def _add_offset(self, offset: BaseOffset) -> Self:
826826 res_unit = self .unit
827827 if hasattr (offset , "offset" ):
828828 offset_td = Timedelta (offset .offset )
829- offset_unit = offset_td .unit
829+ ns = abs (int (offset_td .value )) # Timedelta.value is in nanoseconds
830+ if ns == 0 :
831+ eff_unit = self .unit
832+ elif ns % 1_000_000_000 == 0 :
833+ eff_unit = "s"
834+ elif ns % 1_000_000 == 0 :
835+ eff_unit = "ms"
836+ elif ns % 1_000 == 0 :
837+ eff_unit = "us"
838+ else :
839+ eff_unit = "ns"
840+
830841 idx_self = units .index (self .unit )
831- idx_offset = units .index (offset_unit )
832- res_unit = units [min (idx_self , idx_offset )]
842+ idx_eff = units .index (eff_unit )
843+ res_unit = units [min (idx_self , idx_eff )]
844+
833845 result = type (self )._simple_new (res_values , dtype = res_values .dtype )
834846 result = result .as_unit (res_unit )
835847
You can’t perform that action at this time.
0 commit comments