|
5 | 5 |
|
6 | 6 | from contextlib import contextmanager
|
7 | 7 | from csv import QUOTE_NONE, QUOTE_NONNUMERIC
|
8 |
| -from datetime import tzinfo |
9 | 8 | import decimal
|
10 | 9 | from functools import partial
|
11 | 10 | from io import StringIO
|
|
36 | 35 |
|
37 | 36 | from pandas._libs import lib
|
38 | 37 | from pandas._libs.missing import NA
|
39 |
| -from pandas._libs.tslib import format_array_from_datetime |
40 | 38 | from pandas._libs.tslibs import NaT, Timedelta, Timestamp, iNaT
|
41 | 39 | from pandas._libs.tslibs.nattype import NaTType
|
42 | 40 | from pandas._typing import (
|
@@ -1529,11 +1527,9 @@ def _format_strings(self) -> List[str]:
|
1529 | 1527 | if self.formatter is not None and callable(self.formatter):
|
1530 | 1528 | return [self.formatter(x) for x in values]
|
1531 | 1529 |
|
1532 |
| - fmt_values = format_array_from_datetime( |
1533 |
| - values.asi8.ravel(), |
1534 |
| - format=get_format_datetime64_from_values(values, self.date_format), |
1535 |
| - na_rep=self.nat_rep, |
1536 |
| - ).reshape(values.shape) |
| 1530 | + fmt_values = values._data._format_native_types( |
| 1531 | + na_rep=self.nat_rep, date_format=self.date_format |
| 1532 | + ) |
1537 | 1533 | return fmt_values.tolist()
|
1538 | 1534 |
|
1539 | 1535 |
|
@@ -1653,46 +1649,37 @@ def is_dates_only(
|
1653 | 1649 | return False
|
1654 | 1650 |
|
1655 | 1651 |
|
1656 |
| -def _format_datetime64( |
1657 |
| - x: Union[NaTType, Timestamp], tz: Optional[tzinfo] = None, nat_rep: str = "NaT" |
1658 |
| -) -> str: |
1659 |
| - if x is None or (is_scalar(x) and isna(x)): |
| 1652 | +def _format_datetime64(x: Union[NaTType, Timestamp], nat_rep: str = "NaT") -> str: |
| 1653 | + if x is NaT: |
1660 | 1654 | return nat_rep
|
1661 | 1655 |
|
1662 |
| - if tz is not None or not isinstance(x, Timestamp): |
1663 |
| - if getattr(x, "tzinfo", None) is not None: |
1664 |
| - x = Timestamp(x).tz_convert(tz) |
1665 |
| - else: |
1666 |
| - x = Timestamp(x).tz_localize(tz) |
1667 |
| - |
1668 | 1656 | return str(x)
|
1669 | 1657 |
|
1670 | 1658 |
|
1671 | 1659 | def _format_datetime64_dateonly(
|
1672 |
| - x: Union[NaTType, Timestamp], nat_rep: str = "NaT", date_format: None = None |
| 1660 | + x: Union[NaTType, Timestamp], |
| 1661 | + nat_rep: str = "NaT", |
| 1662 | + date_format: Optional[str] = None, |
1673 | 1663 | ) -> str:
|
1674 |
| - if x is None or (is_scalar(x) and isna(x)): |
| 1664 | + if x is NaT: |
1675 | 1665 | return nat_rep
|
1676 | 1666 |
|
1677 |
| - if not isinstance(x, Timestamp): |
1678 |
| - x = Timestamp(x) |
1679 |
| - |
1680 | 1667 | if date_format:
|
1681 | 1668 | return x.strftime(date_format)
|
1682 | 1669 | else:
|
1683 | 1670 | return x._date_repr
|
1684 | 1671 |
|
1685 | 1672 |
|
1686 | 1673 | def get_format_datetime64(
|
1687 |
| - is_dates_only: bool, nat_rep: str = "NaT", date_format: None = None |
| 1674 | + is_dates_only: bool, nat_rep: str = "NaT", date_format: Optional[str] = None |
1688 | 1675 | ) -> Callable:
|
1689 | 1676 |
|
1690 | 1677 | if is_dates_only:
|
1691 |
| - return lambda x, tz=None: _format_datetime64_dateonly( |
| 1678 | + return lambda x: _format_datetime64_dateonly( |
1692 | 1679 | x, nat_rep=nat_rep, date_format=date_format
|
1693 | 1680 | )
|
1694 | 1681 | else:
|
1695 |
| - return lambda x, tz=None: _format_datetime64(x, tz=tz, nat_rep=nat_rep) |
| 1682 | + return lambda x: _format_datetime64(x, nat_rep=nat_rep) |
1696 | 1683 |
|
1697 | 1684 |
|
1698 | 1685 | def get_format_datetime64_from_values(
|
|
0 commit comments