Skip to content

Followup to #21738 #21764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -1038,6 +1038,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 @@ -1056,7 +1060,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
17 changes: 17 additions & 0 deletions pandas/tests/tslibs/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
"""Tests that the tslibs API is locked down"""

from pandas._libs import tslibs


def test_namespace():
# just check that none of these raise NameErrors
tslibs.normalize_date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do something like this (and match against a fixed list)

In [7]: set([name for name in dir(tslibs) if not name.startswith('_')])
Out[7]: 
{'NaT',
 'OutOfBoundsDatetime',
 'Timedelta',
 'Timestamp',
 'ccalendar',
 'conversion',
 'delta_to_nanoseconds',
 'fields',
 'frequencies',
 'iNaT',
 'ints_to_pytimedelta',
 'localize_pydatetime',
 'nattype',
 'normalize_date',
 'np_datetime',
 'offsets',
 'parsing',
 'period',
 'resolution',
 'strptime',
 'timedeltas',
 'timestamps',
 'timezones',
 'tz_convert_single'}

In [8]: from pandas._libs import tslibs

tslibs.localize_pydatetime
tslibs.tz_convert_single
tslibs.NaT
tslibs.iNaT
tslibs.OutOfBoundsDatetime
tslibs.Timestamp
tslibs.Timedelta
tslibs.delta_to_nanoseconds