diff --git a/pandas/_libs/interval.pyx b/pandas/_libs/interval.pyx index e1ffd450c9a68..0718f8bd2b970 100644 --- a/pandas/_libs/interval.pyx +++ b/pandas/_libs/interval.pyx @@ -109,6 +109,7 @@ cdef class Interval(IntervalMixin): cut, qcut : Convert arrays of continuous data into Categoricals/Series of Interval. """ + _typ = "interval" cdef readonly object left """Left bound for the interval""" diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 1632f5d016439..042b319d51abf 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -49,7 +49,6 @@ PyDateTime_IMPORT from tslibs.np_datetime cimport get_timedelta64_value, get_datetime64_value from tslib import NaT, Timestamp, Timedelta, array_to_datetime -from interval import Interval from missing cimport checknull diff --git a/pandas/_libs/src/inference.pyx b/pandas/_libs/src/inference.pyx index e15f276b39bf8..46d3c2a9c04b2 100644 --- a/pandas/_libs/src/inference.pyx +++ b/pandas/_libs/src/inference.pyx @@ -38,7 +38,7 @@ cpdef bint is_decimal(object obj): cpdef bint is_interval(object obj): - return isinstance(obj, Interval) + return getattr(obj, '_typ', '_typ') == 'interval' cpdef bint is_period(object val): diff --git a/pandas/core/dtypes/generic.py b/pandas/core/dtypes/generic.py index 629d88aa7f086..6fae09c43d2be 100644 --- a/pandas/core/dtypes/generic.py +++ b/pandas/core/dtypes/generic.py @@ -54,6 +54,7 @@ def _check(cls, inst): ABCPeriod = create_pandas_abc_type("ABCPeriod", "_typ", ("period", )) ABCDateOffset = create_pandas_abc_type("ABCDateOffset", "_typ", ("dateoffset",)) +ABCInterval = create_pandas_abc_type("ABCInterval", "_typ", ("interval", )) class _ABCGeneric(type): diff --git a/pandas/tests/dtypes/test_generic.py b/pandas/tests/dtypes/test_generic.py index bd365f9c3281f..58cb182e7d403 100644 --- a/pandas/tests/dtypes/test_generic.py +++ b/pandas/tests/dtypes/test_generic.py @@ -45,6 +45,8 @@ def test_abc_types(self): gt.ABCDateOffset) assert not isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCDateOffset) + assert isinstance(pd.Interval(0, 1.5), gt.ABCInterval) + assert not isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCInterval) def test_setattr_warnings():