Skip to content

Commit c471f17

Browse files
jbrockmendelclaude
andcommitted
BUG: Extract total_ns before try block to avoid duplication
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 182b1bf commit c471f17

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,21 +2192,17 @@ class Timedelta(_Timedelta):
21922192
ns = kwargs.get("nanoseconds", 0)
21932193
us = kwargs.get("microseconds", 0)
21942194
ms = kwargs.get("milliseconds", 0)
2195+
total_ns = (
2196+
int(ns)
2197+
+ int(us * 1_000)
2198+
+ int(ms * 1_000_000)
2199+
+ seconds
2200+
)
2201+
21952202
try:
2196-
value = np.timedelta64(
2197-
int(ns)
2198-
+ int(us * 1_000)
2199-
+ int(ms * 1_000_000)
2200-
+ seconds, "ns"
2201-
)
2203+
value = np.timedelta64(total_ns, "ns")
22022204
except OverflowError:
22032205
# GH#46587 - fall back to coarser resolutions
2204-
total_ns = (
2205-
int(ns)
2206-
+ int(us * 1_000)
2207-
+ int(ms * 1_000_000)
2208-
+ seconds
2209-
)
22102206
if total_ns % 1_000 != 0:
22112207
reso_value, reso_abbrev = total_ns, "ns"
22122208
elif total_ns % 1_000_000 != 0:

0 commit comments

Comments
 (0)