Skip to content

CLN: remove simple _DATELIKE_DTYPES test and replace with is_datetimelike accessor #14909

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from pandas.compat.numpy import function as nv
from pandas.compat.numpy import _np_version_under1p8

from pandas.types.common import (_DATELIKE_DTYPES,
is_numeric_dtype,
from pandas.types.common import (is_numeric_dtype,
is_timedelta64_dtype, is_datetime64_dtype,
is_categorical_dtype,
is_datetimelike,
is_datetime_or_timedelta_dtype,
is_bool, is_integer_dtype,
is_complex_dtype,
Expand Down Expand Up @@ -3453,10 +3453,10 @@ def first_non_None_value(values):
# if we have date/time like in the original, then coerce dates
# as we are stacking can easily have object dtypes here
so = self._selected_obj
if (so.ndim == 2 and so.dtypes.isin(_DATELIKE_DTYPES).any()):
if (so.ndim == 2 and so.dtypes.apply(is_datetimelike).any()):
result = result._convert(numeric=True)
date_cols = self._selected_obj.select_dtypes(
include=list(_DATELIKE_DTYPES)).columns
include=['datetime', 'timedelta']).columns
date_cols = date_cols.intersection(result.columns)
result[date_cols] = (result[date_cols]
._convert(datetime=True,
Expand Down
7 changes: 4 additions & 3 deletions pandas/types/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pandas.compat import string_types, text_type, PY3
from .common import (_ensure_object, is_bool, is_integer, is_float,
is_complex, is_datetimetz, is_categorical_dtype,
is_datetimelike,
is_extension_type, is_object_dtype,
is_datetime64tz_dtype, is_datetime64_dtype,
is_timedelta64_dtype, is_dtype_equal,
Expand All @@ -18,7 +19,7 @@
_ensure_int8, _ensure_int16,
_ensure_int32, _ensure_int64,
_NS_DTYPE, _TD_DTYPE, _INT64_DTYPE,
_DATELIKE_DTYPES, _POSSIBLY_CAST_DTYPES)
_POSSIBLY_CAST_DTYPES)
from .dtypes import ExtensionDtype
from .generic import ABCDatetimeIndex, ABCPeriodIndex, ABCSeries
from .missing import isnull, notnull
Expand Down Expand Up @@ -164,7 +165,7 @@ def _maybe_upcast_putmask(result, mask, other):
# in np.place:
# NaN -> NaT
# integer or integer array -> date-like array
if result.dtype in _DATELIKE_DTYPES:
if is_datetimelike(result.dtype):
if is_scalar(other):
if isnull(other):
other = result.dtype.type('nat')
Expand Down Expand Up @@ -666,7 +667,7 @@ def _possibly_castable(arr):
# otherwise try to coerce
kind = arr.dtype.kind
if kind == 'M' or kind == 'm':
return arr.dtype in _DATELIKE_DTYPES
return is_datetime64_dtype(arr.dtype)

return arr.dtype.name not in _POSSIBLY_CAST_DTYPES

Expand Down
7 changes: 2 additions & 5 deletions pandas/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
_TD_DTYPE = np.dtype('m8[ns]')
_INT64_DTYPE = np.dtype(np.int64)

_DATELIKE_DTYPES = set([np.dtype(t)
for t in ['M8[ns]', '<M8[ns]', '>M8[ns]',
'm8[ns]', '<m8[ns]', '>m8[ns]']])

_ensure_float64 = algos.ensure_float64
_ensure_float32 = algos.ensure_float32

Expand Down Expand Up @@ -127,7 +123,8 @@ def is_datetime_arraylike(arr):


def is_datetimelike(arr):
return (arr.dtype in _DATELIKE_DTYPES or
return (is_datetime64_dtype(arr) or is_datetime64tz_dtype(arr) or
is_timedelta64_dtype(arr) or
isinstance(arr, ABCPeriodIndex) or
is_datetimetz(arr))

Expand Down
5 changes: 2 additions & 3 deletions pandas/types/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
is_object_dtype,
is_integer,
_TD_DTYPE,
_NS_DTYPE,
_DATELIKE_DTYPES)
_NS_DTYPE)
from .inference import is_list_like


Expand Down Expand Up @@ -169,7 +168,7 @@ def _isnull_ndarraylike_old(obj):
vec = lib.isnullobj_old(values.ravel())
result[:] = vec.reshape(shape)

elif dtype in _DATELIKE_DTYPES:
elif is_datetime64_dtype(dtype):
# this is the NaT pattern
result = values.view('i8') == iNaT
else:
Expand Down