From 3fb5a2cd05522b7fee8d79ff31654715b5d5c1f4 Mon Sep 17 00:00:00 2001 From: Pranav Wadhwa <25285598+Pranav-Wadhwa@users.noreply.github.com> Date: Fri, 16 Aug 2024 12:04:49 -0400 Subject: [PATCH] Attempt unit us to_datetime --- pandas/core/tools/datetimes.py | 2 +- pandas/tests/tools/test_to_datetime.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 9b8970f86ed6d..7a69fe33b90bb 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -672,7 +672,7 @@ def to_datetime( utc: bool = False, format: str | None = None, exact: bool | lib.NoDefault = lib.no_default, - unit: str | None = None, + unit: str | None = "us", origin: str = "unix", cache: bool = True, ) -> DatetimeIndex | Series | DatetimeScalar | NaTType | None: diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index c1d6baaf17c92..dce09f70e491b 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1714,6 +1714,19 @@ def test_to_datetime_mixed_offsets_with_utc_false_removed(self, date): with pytest.raises(ValueError, match=msg): to_datetime(date, utc=False) + @pytest.mark.parametrize( + "date", + [ + "2024-03-22 11:43:01", + "2024-03-22 11:43:01.002", + "2024-03-22 11:43:01.002003", + ], + ) + def test_to_datetime_type(self, date): + dt = to_datetime([date]) + print("pranav dtype is ", dt.dtype) + assert dt.dtype == "