diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 0076ec74ea9e1..9964ca0847ce7 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -1045,6 +1045,10 @@ def normalize_date(object dt): Returns ------- normalized : datetime.datetime or Timestamp + + Raises + ------ + TypeError : if input is not datetime.date, datetime.datetime, or Timestamp """ if PyDateTime_Check(dt): if not PyDateTime_CheckExact(dt): @@ -1063,7 +1067,7 @@ def normalize_date(object dt): @cython.wraparound(False) @cython.boundscheck(False) -def date_normalize(ndarray[int64_t] stamps, tz=None): +def normalize_i8_timestamps(ndarray[int64_t] stamps, tz=None): """ Normalize each of the (nanosecond) timestamps in the given array by rounding down to the beginning of the day (i.e. midnight). If `tz` diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 401ba76e341b2..711db7cc8fbe2 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -21,7 +21,7 @@ from util cimport (is_datetime64_object, is_timedelta64_object, INT64_MAX) cimport ccalendar -from conversion import tz_localize_to_utc, date_normalize +from conversion import tz_localize_to_utc, normalize_i8_timestamps from conversion cimport (tz_convert_single, _TSObject, convert_to_tsobject, convert_datetime_to_tsobject) from fields import get_start_end_field, get_date_name_field @@ -1083,7 +1083,7 @@ class Timestamp(_Timestamp): Normalize Timestamp to midnight, preserving tz information. """ - normalized_value = date_normalize( + normalized_value = normalize_i8_timestamps( np.array([self.value], dtype='i8'), tz=self.tz)[0] return Timestamp(normalized_value).tz_localize(self.tz) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 05f7af6383211..966eff58262e8 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -2002,7 +2002,7 @@ def normalize(self): '2014-08-01 00:00:00+05:30'], dtype='datetime64[ns, Asia/Calcutta]', freq=None) """ - new_values = conversion.date_normalize(self.asi8, self.tz) + new_values = conversion.normalize_i8_timestamps(self.asi8, self.tz) return DatetimeIndex(new_values, freq='infer', name=self.name).tz_localize(self.tz) diff --git a/pandas/tests/tslibs/test_api.py b/pandas/tests/tslibs/test_api.py new file mode 100644 index 0000000000000..387a63f61179d --- /dev/null +++ b/pandas/tests/tslibs/test_api.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +"""Tests that the tslibs API is locked down""" + +from pandas._libs import tslibs + + +def test_namespace(): + + submodules = ['ccalendar', + 'conversion', + 'fields', + 'frequencies', + 'nattype', + 'np_datetime', + 'offsets', + 'parsing', + 'period', + 'resolution', + 'strptime', + 'timedeltas', + 'timestamps', + 'timezones'] + + api = ['NaT', + 'iNaT', + 'OutOfBoundsDatetime', + 'Timedelta', + 'Timestamp', + 'delta_to_nanoseconds', + 'ints_to_pytimedelta', + 'localize_pydatetime', + 'normalize_date', + 'tz_convert_single'] + + expected = set(submodules + api) + names = [x for x in dir(tslibs) if not x.startswith('__')] + assert set(names) == expected