Skip to content

CLN: using C-API of datetime #33174

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 3 commits into from
Mar 31, 2020
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
5 changes: 2 additions & 3 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ cnp.import_array()
import pytz

# stdlib datetime imports
from datetime import time as datetime_time
from cpython.datetime cimport (datetime, tzinfo,
from cpython.datetime cimport (datetime, time, tzinfo,
PyDateTime_Check, PyDate_Check,
PyDateTime_IMPORT)
PyDateTime_IMPORT
Expand Down Expand Up @@ -284,7 +283,7 @@ cdef convert_to_tsobject(object ts, object tz, object unit,
return convert_datetime_to_tsobject(ts, tz, nanos)
elif PyDate_Check(ts):
# Keep the converter same as PyDateTime's
ts = datetime.combine(ts, datetime_time())
ts = datetime.combine(ts, time())
return convert_datetime_to_tsobject(ts, tz)
elif getattr(ts, '_typ', None) == 'period':
raise ValueError("Cannot convert Period to Timestamp "
Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datetime import datetime

from cpython.object cimport PyObject_RichCompareBool, Py_EQ, Py_NE

from numpy cimport int64_t, import_array, ndarray
Expand All @@ -13,6 +11,7 @@ from libc.string cimport strlen, memset
import cython

from cpython.datetime cimport (
datetime,
PyDate_Check,
PyDateTime_Check,
PyDateTime_IMPORT,
Expand Down
8 changes: 3 additions & 5 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ cimport numpy as cnp
from numpy cimport int64_t
cnp.import_array()

from datetime import time as datetime_time, timedelta
from cpython.datetime cimport (datetime, PyDateTime_Check,
from cpython.datetime cimport (datetime, time, PyDateTime_Check, PyDelta_Check,
PyTZInfo_Check, PyDateTime_IMPORT)
PyDateTime_IMPORT

Expand All @@ -33,7 +32,7 @@ from pandas._libs.tslibs.tzconversion import (

# ----------------------------------------------------------------------
# Constants
_zero_time = datetime_time(0, 0)
_zero_time = time(0, 0)
_no_input = object()

# ----------------------------------------------------------------------
Expand Down Expand Up @@ -879,8 +878,7 @@ default 'raise'
raise ValueError('Cannot infer offset with only one time.')

nonexistent_options = ('raise', 'NaT', 'shift_forward', 'shift_backward')
if nonexistent not in nonexistent_options and not isinstance(
nonexistent, timedelta):
if nonexistent not in nonexistent_options and not PyDelta_Check(nonexistent):
raise ValueError(
"The nonexistent argument must be one of 'raise', "
"'NaT', 'shift_forward', 'shift_backward' or a timedelta object"
Expand Down