Skip to content

CLN: Remove util.is_offset_object #34241

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 20, 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: 3 additions & 2 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ cnp.import_array()
from pandas._libs cimport util

from pandas._libs.tslibs.nattype cimport c_NaT as NaT
from pandas._libs.tslibs.base cimport ABCTimestamp, ABCTimedelta
from pandas._libs.tslibs.base cimport ABCTimedelta
from pandas._libs.tslibs.period cimport is_period_object
from pandas._libs.tslibs.timestamps cimport _Timestamp

from pandas._libs.hashtable cimport HashTable

Expand Down Expand Up @@ -378,7 +379,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, ABCTimestamp) or scalar is NaT):
if not (isinstance(scalar, _Timestamp) or scalar is NaT):
raise TypeError(scalar)
return scalar.value

Expand Down
10 changes: 5 additions & 5 deletions pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ from pandas._libs.tslibs.util cimport (
is_timedelta64_object,
)

from pandas._libs.tslibs.base cimport ABCTimestamp, ABCTimedelta
from pandas._libs.tslibs.base cimport ABCTimedelta
from pandas._libs.tslibs.timezones cimport tz_compare

from pandas._libs.tslibs.timestamps cimport _Timestamp

_VALID_CLOSED = frozenset(['left', 'right', 'both', 'neither'])

Expand Down Expand Up @@ -328,7 +328,7 @@ cdef class Interval(IntervalMixin):
raise ValueError(f"invalid option for 'closed': {closed}")
if not left <= right:
raise ValueError("left side of interval must be <= right side")
if (isinstance(left, ABCTimestamp) and
if (isinstance(left, _Timestamp) and
not tz_compare(left.tzinfo, right.tzinfo)):
# GH 18538
raise ValueError("left and right must have the same time zone, got "
Expand All @@ -340,7 +340,7 @@ cdef class Interval(IntervalMixin):
def _validate_endpoint(self, endpoint):
# GH 23013
if not (is_integer_object(endpoint) or is_float_object(endpoint) or
isinstance(endpoint, (ABCTimestamp, ABCTimedelta))):
isinstance(endpoint, (_Timestamp, ABCTimedelta))):
raise ValueError("Only numeric, Timestamp and Timedelta endpoints "
"are allowed when constructing an Interval.")

Expand Down Expand Up @@ -370,7 +370,7 @@ cdef class Interval(IntervalMixin):
right = self.right

# TODO: need more general formatting methodology here
if isinstance(left, ABCTimestamp) and isinstance(right, ABCTimestamp):
if isinstance(left, _Timestamp) and isinstance(right, _Timestamp):
left = left._short_repr
right = right._short_repr

Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ from pandas._libs.tslibs.conversion cimport convert_to_tsobject
from pandas._libs.tslibs.timedeltas cimport convert_to_timedelta64
from pandas._libs.tslibs.timezones cimport get_timezone, tz_compare
from pandas._libs.tslibs.period cimport is_period_object
from pandas._libs.tslibs.offsets cimport is_offset_object

from pandas._libs.missing cimport (
checknull,
Expand Down Expand Up @@ -187,7 +188,7 @@ def is_scalar(val: object) -> bool:
return (PyNumber_Check(val)
or is_period_object(val)
or is_interval(val)
or util.is_offset_object(val))
or is_offset_object(val))


def is_iterator(obj: object) -> bool:
Expand Down
6 changes: 2 additions & 4 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ from pandas._libs.util cimport (
is_integer_object,
)

from pandas._libs.tslibs.base cimport ABCTimestamp

from pandas._libs.tslibs.np_datetime cimport (
_string_to_dts,
check_dts_bounds,
Expand Down Expand Up @@ -58,7 +56,7 @@ from pandas._libs.tslibs.nattype cimport (

from pandas._libs.tslibs.offsets cimport to_offset

from pandas._libs.tslibs.timestamps cimport create_timestamp_from_ts
from pandas._libs.tslibs.timestamps cimport create_timestamp_from_ts, _Timestamp
from pandas._libs.tslibs.timestamps import Timestamp

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

Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/frequencies.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import re
cimport numpy as cnp
cnp.import_array()

from pandas._libs.tslibs.util cimport is_integer_object, is_offset_object
from pandas._libs.tslibs.util cimport is_integer_object

from pandas._libs.tslibs.ccalendar cimport c_MONTH_NUMBERS
from pandas._libs.tslibs.offsets cimport is_offset_object

# ----------------------------------------------------------------------
# Constants
Expand Down
8 changes: 2 additions & 6 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ cdef class _NaT(datetime):
return c_NaT
elif util.is_datetime64_object(other) or util.is_timedelta64_object(other):
return c_NaT
elif util.is_offset_object(other):
return c_NaT

elif util.is_integer_object(other):
# For Period compat
Expand All @@ -162,7 +160,7 @@ cdef class _NaT(datetime):
return result
raise TypeError(f"Cannot add NaT to ndarray with dtype {other.dtype}")

# Includes Period going through here
# Includes Period, DateOffset going through here
return NotImplemented

def __sub__(self, other):
Expand All @@ -182,8 +180,6 @@ cdef class _NaT(datetime):
return c_NaT
elif util.is_datetime64_object(other) or util.is_timedelta64_object(other):
return c_NaT
elif util.is_offset_object(other):
return c_NaT

elif util.is_integer_object(other):
# For Period compat
Expand Down Expand Up @@ -216,7 +212,7 @@ cdef class _NaT(datetime):
f"Cannot subtract NaT from ndarray with dtype {other.dtype}"
)

# Includes Period going through here
# Includes Period, DateOffset going through here
return NotImplemented

def __pos__(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ from pandas._libs.tslibs.nattype cimport (
)
from pandas._libs.tslibs.util cimport (
is_array,
is_offset_object,
get_c_string_buf_and_size,
)
from pandas._libs.tslibs.frequencies cimport get_rule_month
from pandas._libs.tslibs.offsets cimport is_offset_object

cdef extern from "../src/headers/portable.h":
int getdigit_ascii(char c, int default) nogil
Expand Down
10 changes: 6 additions & 4 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ from pandas._libs.tslibs.nattype cimport (
c_NaT as NaT,
c_nat_strings as nat_strings,
)
from pandas._libs.tslibs.offsets cimport to_offset, is_tick_object
from pandas._libs.tslibs.offsets cimport (
to_offset, is_tick_object, is_offset_object,
)
from pandas._libs.tslibs.tzconversion cimport tz_convert_utc_to_tzlocal


Expand Down Expand Up @@ -1598,7 +1600,7 @@ cdef class _Period:
return Period(ordinal=ordinal, freq=self.freq)
raise IncompatibleFrequency("Input cannot be converted to "
f"Period(freq={self.freqstr})")
elif util.is_offset_object(other):
elif is_offset_object(other):
if other.base == self.freq.base:
ordinal = self.ordinal + other.n
return Period(ordinal=ordinal, freq=self.freq)
Expand All @@ -1617,7 +1619,7 @@ cdef class _Period:
return other.__add__(self)

if (PyDelta_Check(other) or util.is_timedelta64_object(other) or
util.is_offset_object(other)):
is_offset_object(other)):
return self._add_delta(other)
elif other is NaT:
return NaT
Expand All @@ -1643,7 +1645,7 @@ cdef class _Period:
return NotImplemented

elif (PyDelta_Check(other) or util.is_timedelta64_object(other) or
util.is_offset_object(other)):
is_offset_object(other)):
neg_other = -other
return self + neg_other
elif util.is_integer_object(other):
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 cpython.datetime cimport (datetime, time, PyDateTime_Check, PyDelta_Check,
PyDateTime_IMPORT

from pandas._libs.tslibs.util cimport (
is_datetime64_object, is_float_object, is_integer_object, is_offset_object,
is_datetime64_object, is_float_object, is_integer_object,
is_timedelta64_object, is_array,
)

Expand All @@ -40,7 +40,7 @@ from pandas._libs.tslibs.np_datetime cimport (
cmp_scalar,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.offsets cimport to_offset, is_tick_object
from pandas._libs.tslibs.offsets cimport to_offset, is_tick_object, is_offset_object
from pandas._libs.tslibs.timedeltas import Timedelta
from pandas._libs.tslibs.timezones cimport (
is_utc, maybe_get_tz, treat_tz_as_pytz, utc_pytz as UTC,
Expand Down
15 changes: 0 additions & 15 deletions pandas/_libs/tslibs/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,6 @@ cdef inline bint is_array(object val):
return PyArray_Check(val)


cdef inline bint is_offset_object(object val):
"""
Check if an object is a DateOffset object.

Parameters
----------
val : object

Returns
-------
is_date_offset : bool
"""
return getattr(val, '_typ', None) == "dateoffset"


cdef inline bint is_nan(object val):
"""
Check if val is a Not-A-Number float or complex, including
Expand Down