diff --git a/pandas/_libs/tslibs/__init__.py b/pandas/_libs/tslibs/__init__.py index 4a4e53eaa45fa..47b35aa6eabff 100644 --- a/pandas/_libs/tslibs/__init__.py +++ b/pandas/_libs/tslibs/__init__.py @@ -1,6 +1,5 @@ __all__ = [ "localize_pydatetime", - "normalize_date", "NaT", "NaTType", "iNaT", @@ -17,7 +16,7 @@ ] -from .conversion import localize_pydatetime, normalize_date +from .conversion import localize_pydatetime from .nattype import NaT, NaTType, iNaT, is_null_datetimelike from .np_datetime import OutOfBoundsDatetime from .period import IncompatibleFrequency, Period diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index f7408e69f7dec..8a1cacfe304ca 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1,5 +1,5 @@ from datetime import datetime, time, timedelta -from typing import Union +from typing import Optional, Union import warnings import numpy as np @@ -13,7 +13,6 @@ conversion, fields, iNaT, - normalize_date, resolution as libresolution, timezones, tzconversion, @@ -2288,19 +2287,21 @@ def _infer_tz_from_endpoints(start, end, tz): return tz -def _maybe_normalize_endpoints(start, end, normalize): +def _maybe_normalize_endpoints( + start: Optional[Timestamp], end: Optional[Timestamp], normalize: bool +): _normalized = True if start is not None: if normalize: - start = normalize_date(start) + start = start.normalize() _normalized = True else: _normalized = _normalized and start.time() == _midnight if end is not None: if normalize: - end = normalize_date(end) + end = end.normalize() _normalized = True else: _normalized = _normalized and end.time() == _midnight diff --git a/pandas/tests/tslibs/test_api.py b/pandas/tests/tslibs/test_api.py index 7a8a6d511aa69..a4c2e3f0787d0 100644 --- a/pandas/tests/tslibs/test_api.py +++ b/pandas/tests/tslibs/test_api.py @@ -38,7 +38,6 @@ def test_namespace(): "delta_to_nanoseconds", "ints_to_pytimedelta", "localize_pydatetime", - "normalize_date", "tz_convert_single", ] diff --git a/pandas/tests/tslibs/test_normalize_date.py b/pandas/tests/tslibs/test_normalize_date.py deleted file mode 100644 index 2a41836f456ec..0000000000000 --- a/pandas/tests/tslibs/test_normalize_date.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Tests for functions from pandas._libs.tslibs""" - -from datetime import date, datetime - -import pytest - -from pandas._libs import tslibs -from pandas._libs.tslibs.timestamps import Timestamp - - -@pytest.mark.parametrize( - "value,expected", - [ - (date(2012, 9, 7), datetime(2012, 9, 7)), - (datetime(2012, 9, 7, 12), datetime(2012, 9, 7)), - (datetime(2007, 10, 1, 1, 12, 5, 10), datetime(2007, 10, 1)), - ], -) -def test_normalize_date(value, expected): - result = tslibs.normalize_date(value) - assert result == expected - - -class SubDatetime(datetime): - pass - - -@pytest.mark.parametrize( - "dt, expected", - [ - (Timestamp(2000, 1, 1, 1), Timestamp(2000, 1, 1, 0)), - (datetime(2000, 1, 1, 1), datetime(2000, 1, 1, 0)), - (SubDatetime(2000, 1, 1, 1), SubDatetime(2000, 1, 1, 0)), - ], -) -def test_normalize_date_sub_types(dt, expected): - # GH 25851 - # ensure that subclassed datetime works with - # normalize_date - result = tslibs.normalize_date(dt) - assert result == expected