Skip to content

Commit d302fe1

Browse files
author
Sylvain MARIE
committed
Added maintenance comments
1 parent 9851b36 commit d302fe1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pandas/io/formats/format.py

+8
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,8 @@ def _format_datetime64(x: NaTType | Timestamp, nat_rep: str = "NaT") -> str:
17591759
if x is NaT:
17601760
return nat_rep
17611761

1762+
# Timestamp.__str__ falls back to datetime.datetime.__str__ = isoformat(sep=' ')
1763+
# so it already uses string formatting rather than strftime (faster).
17621764
return str(x)
17631765

17641766

@@ -1773,12 +1775,15 @@ def _format_datetime64_dateonly(
17731775
if date_format:
17741776
return x.strftime(date_format)
17751777
else:
1778+
# Timestamp._date_repr relies on string formatting (faster than strftime)
17761779
return x._date_repr
17771780

17781781

17791782
def get_format_datetime64(
17801783
is_dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None
17811784
) -> Callable:
1785+
"""Return a formatter callable taking a datetime64 as input and providing
1786+
a string as output"""
17821787

17831788
if is_dates_only:
17841789
return lambda x: _format_datetime64_dateonly(
@@ -1799,6 +1804,7 @@ def get_format_datetime64_from_values(
17991804

18001805
ido = is_dates_only(values)
18011806
if ido:
1807+
# Only dates and no timezone: provide a default format
18021808
return date_format or "%Y-%m-%d"
18031809
return date_format
18041810

@@ -1872,6 +1878,8 @@ def _formatter(x):
18721878

18731879
if not isinstance(x, Timedelta):
18741880
x = Timedelta(x)
1881+
1882+
# Timedelta._repr_base uses string formatting (faster than strftime)
18751883
result = x._repr_base(format=format)
18761884
if box:
18771885
result = f"'{result}'"

0 commit comments

Comments
 (0)