Skip to content
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

Improve use of isinstance. #10734

Merged
merged 1 commit into from
Apr 26, 2022
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
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