Skip to content

REF: implement ABCTimestamp, ABCTimedelta, ABCTick #34054

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 4 commits into from
May 7, 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
4 changes: 2 additions & 2 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cimport pandas._libs.util as util

from pandas._libs.tslibs import Period, Timedelta
from pandas._libs.tslibs.nattype cimport c_NaT as NaT
from pandas._libs.tslibs.c_timestamp cimport _Timestamp
from pandas._libs.tslibs.base cimport ABCTimestamp

from pandas._libs.hashtable cimport HashTable

Expand Down Expand Up @@ -378,7 +378,7 @@ cdef class DatetimeEngine(Int64Engine):
cdef int64_t _unbox_scalar(self, scalar) except? -1:
# NB: caller is responsible for ensuring tzawareness compat
# before we get here
if not (isinstance(scalar, _Timestamp) or scalar is NaT):
if not (isinstance(scalar, ABCTimestamp) or scalar is NaT):
raise TypeError(scalar)
return scalar.value

Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from pandas._libs.util cimport (
is_integer_object,
)

from pandas._libs.tslibs.c_timestamp cimport _Timestamp
from pandas._libs.tslibs.base cimport ABCTimestamp

from pandas._libs.tslibs.np_datetime cimport (
_string_to_dts,
Expand Down Expand Up @@ -617,7 +617,7 @@ cpdef array_to_datetime(
'datetime64 unless utc=True')
else:
iresult[i] = pydatetime_to_dt64(val, &dts)
if isinstance(val, _Timestamp):
if isinstance(val, ABCTimestamp):
iresult[i] += val.nanosecond
check_dts_bounds(&dts)

Expand Down
5 changes: 1 addition & 4 deletions pandas/_libs/tslibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@
from .np_datetime import OutOfBoundsDatetime
from .period import IncompatibleFrequency, Period
from .timedeltas import Timedelta, delta_to_nanoseconds, ints_to_pytimedelta
from .timestamps import Timestamp
from .timestamps import NullFrequencyError, Timestamp
from .tzconversion import tz_convert_single

# import fails if we do this before np_datetime
from .c_timestamp import NullFrequencyError # isort:skip
20 changes: 20 additions & 0 deletions pandas/_libs/tslibs/base.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from cpython.datetime cimport datetime, timedelta

cdef class ABCTimedelta(timedelta):
Copy link
Contributor

Choose a reason for hiding this comment

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

ic, so now we have a cdef class that we can do instance on w/o having to import the world, nice.

pass


cdef class ABCTimestamp(datetime):
pass


cdef class ABCTick:
pass


cdef class ABCPeriod:
pass


cdef bint is_tick_object(object obj)
cdef bint is_period_object(object obj)
32 changes: 32 additions & 0 deletions pandas/_libs/tslibs/base.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
We define base classes that will be inherited by Timestamp, Timedelta, etc
in order to allow for fast isinstance checks without circular dependency issues.

This is analogous to core.dtypes.generic.
"""

from cpython.datetime cimport datetime, timedelta


cdef class ABCTimedelta(timedelta):
pass


cdef class ABCTimestamp(datetime):
pass


cdef class ABCPeriod:
pass


cdef class ABCTick:
pass


cdef bint is_tick_object(object obj):
return isinstance(obj, ABCTick)


cdef bint is_period_object(object obj):
return isinstance(obj, ABCPeriod)
17 changes: 0 additions & 17 deletions pandas/_libs/tslibs/c_timestamp.pxd

This file was deleted.

Loading