Skip to content

Commit

Permalink
Improve use of isinstance.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdice committed Apr 26, 2022
1 parent ac27757 commit 8e0c9e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
30 changes: 14 additions & 16 deletions python/cudf/cudf/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,12 @@ def is_numeric_dtype(obj):
if issubclass(obj, _BaseDtype):
return False
else:
if isinstance(obj, cudf.Decimal128Dtype) or isinstance(
getattr(obj, "dtype", None), cudf.Decimal128Dtype
):
return True
if isinstance(obj, cudf.Decimal64Dtype) or isinstance(
getattr(obj, "dtype", None), cudf.Decimal64Dtype
):
return True
if isinstance(obj, cudf.Decimal32Dtype) or isinstance(
getattr(obj, "dtype", None), cudf.Decimal32Dtype
if isinstance(
obj,
(cudf.Decimal128Dtype, cudf.Decimal64Dtype, cudf.Decimal32Dtype),
) or isinstance(
getattr(obj, "dtype", None),
(cudf.Decimal128Dtype, cudf.Decimal64Dtype, cudf.Decimal32Dtype),
):
return True
if isinstance(obj, _BaseDtype) or isinstance(
Expand Down Expand Up @@ -129,12 +125,14 @@ def is_scalar(val):
bool
Return True if given object is scalar.
"""
return (
isinstance(val, cudf._lib.scalar.DeviceScalar)
or isinstance(val, cudf.Scalar)
or isinstance(val, cudf.core.tools.datetimes.DateOffset)
or pd_types.is_scalar(val)
)
return isinstance(
val,
(
cudf.Scalar,
cudf._lib.scalar.DeviceScalar,
cudf.core.tools.datetimes.DateOffset,
),
) or pd_types.is_scalar(val)


def _is_scalar_or_zero_d_array(val):
Expand Down
9 changes: 7 additions & 2 deletions python/cudf/cudf/core/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,13 @@ def is_interval_dtype(obj):
# TODO: Should there be any branch in this function that calls
# pd.api.types.is_interval_dtype?
return (
isinstance(obj, cudf.core.dtypes.IntervalDtype)
or isinstance(obj, pd.core.dtypes.dtypes.IntervalDtype)
isinstance(
obj,
(
cudf.core.dtypes.IntervalDtype,
pd.core.dtypes.dtypes.IntervalDtype,
),
)
or obj is cudf.core.dtypes.IntervalDtype
or (
isinstance(obj, str) and obj == cudf.core.dtypes.IntervalDtype.name
Expand Down

0 comments on commit 8e0c9e3

Please sign in to comment.