Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions pandas/tests/tslibs/test_api.py
Original file line number Diff line number Diff line change
@@ -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