File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -1759,6 +1759,8 @@ def _format_datetime64(x: NaTType | Timestamp, nat_rep: str = "NaT") -> str:
1759
1759
if x is NaT :
1760
1760
return nat_rep
1761
1761
1762
+ # Timestamp.__str__ falls back to datetime.datetime.__str__ = isoformat(sep=' ')
1763
+ # so it already uses string formatting rather than strftime (faster).
1762
1764
return str (x )
1763
1765
1764
1766
@@ -1773,12 +1775,15 @@ def _format_datetime64_dateonly(
1773
1775
if date_format :
1774
1776
return x .strftime (date_format )
1775
1777
else :
1778
+ # Timestamp._date_repr relies on string formatting (faster than strftime)
1776
1779
return x ._date_repr
1777
1780
1778
1781
1779
1782
def get_format_datetime64 (
1780
1783
is_dates_only : bool , nat_rep : str = "NaT" , date_format : str | None = None
1781
1784
) -> Callable :
1785
+ """Return a formatter callable taking a datetime64 as input and providing
1786
+ a string as output"""
1782
1787
1783
1788
if is_dates_only :
1784
1789
return lambda x : _format_datetime64_dateonly (
@@ -1799,6 +1804,7 @@ def get_format_datetime64_from_values(
1799
1804
1800
1805
ido = is_dates_only (values )
1801
1806
if ido :
1807
+ # Only dates and no timezone: provide a default format
1802
1808
return date_format or "%Y-%m-%d"
1803
1809
return date_format
1804
1810
@@ -1872,6 +1878,8 @@ def _formatter(x):
1872
1878
1873
1879
if not isinstance (x , Timedelta ):
1874
1880
x = Timedelta (x )
1881
+
1882
+ # Timedelta._repr_base uses string formatting (faster than strftime)
1875
1883
result = x ._repr_base (format = format )
1876
1884
if box :
1877
1885
result = f"'{ result } '"
You can’t perform that action at this time.
0 commit comments