(
date_col,
col: Hashable,
dayfirst: bool = False,
cache_dates: bool = True,
date_format: dict[Hashable, str] | str | None = None,
)
| 761 | |
| 762 | |
| 763 | def date_converter( |
| 764 | date_col, |
| 765 | col: Hashable, |
| 766 | dayfirst: bool = False, |
| 767 | cache_dates: bool = True, |
| 768 | date_format: dict[Hashable, str] | str | None = None, |
| 769 | ): |
| 770 | if date_col.dtype.kind in "Mm": |
| 771 | return date_col |
| 772 | |
| 773 | date_fmt = date_format.get(col) if isinstance(date_format, dict) else date_format |
| 774 | |
| 775 | str_objs = lib.ensure_string_array(np.asarray(date_col)) |
| 776 | try: |
| 777 | result = tools.to_datetime( |
| 778 | str_objs, |
| 779 | format=date_fmt, |
| 780 | utc=False, |
| 781 | dayfirst=dayfirst, |
| 782 | cache=cache_dates, |
| 783 | ) |
| 784 | except (ValueError, TypeError): |
| 785 | # test_usecols_with_parse_dates4 |
| 786 | # test_multi_index_parse_dates |
| 787 | return str_objs |
| 788 | |
| 789 | if isinstance(result, DatetimeIndex): |
| 790 | arr = result.to_numpy() |
| 791 | arr.flags.writeable = True |
| 792 | return arr |
| 793 | return result._values |
| 794 | |
| 795 | |
| 796 | parser_defaults = { |
no test coverage detected