Skip to content

Commit 7c70748

Browse files
committed
Implement replace and adjusted for timedelta pandas-dev#57188
Co-authored by: Sofia Simas <[email protected]>
1 parent b62e5a7 commit 7c70748

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pandas/core/indexes/accessors.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,12 @@ def adjusted(self):
519519
td.components.microseconds * 1000 +
520520
td.components.nanoseconds
521521
)
522-
time_str = f"{td.components.seconds:02d}.{td.components.milliseconds:03d}\
523-
{td.components.microseconds:03d}{td.components.nanoseconds:03d}"
522+
time_str = (
523+
f"{td.components.seconds:02d}."
524+
f"{td.components.milliseconds:03d}"
525+
f"{td.components.microseconds:03d}"
526+
f"{td.components.nanoseconds:03d}"
527+
)
524528
if len(time_str) > max_seconds_length:
525529
max_seconds_length = len(time_str)
526530

@@ -535,13 +539,20 @@ def adjusted(self):
535539
nanoseconds = td.components.nanoseconds
536540

537541
# Construct combined time string with leading zeros
538-
seconds_str = f"{seconds:02d}.{milliseconds:03d}{microseconds:03d}\
539-
{nanoseconds:03d}"
542+
seconds_str = (
543+
f"{seconds:02d}."
544+
f"{milliseconds:03d}"
545+
f"{microseconds:03d}"
546+
f"{nanoseconds:03d}"
547+
)
540548
seconds_str = seconds_str.ljust(max_seconds_length, '0')
541549

542550
# Format timedelta string with aligned days and padded time components
543-
formatted_td.append(f"{days:>{max_days_length}} days {hours:02d}:{minutes:02d}\
544-
:{seconds_str}")
551+
formatted_td.append(
552+
f"{days:>{max_days_length}} days "
553+
f"{hours:02d}:{minutes:02d}:"
554+
f"{seconds_str}"
555+
)
545556

546557
return pd.Series(formatted_td)
547558

0 commit comments

Comments
 (0)