Skip to content

Commit

Permalink
Remove aliases of various api.types APIs from utils.dtypes. (#9011)
Browse files Browse the repository at this point in the history
Continuation of #8308 that moves all imports of standard dtype utilities to use `cudf.api.types` or `cudf.core.dtypes` rather than `cudf.util.dtypes`.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Ashwin Srinath (https://github.com/shwina)
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #9011
  • Loading branch information
vyasr committed Sep 15, 2021
1 parent a855660 commit 945b28b
Show file tree
Hide file tree
Showing 48 changed files with 158 additions and 170 deletions.
2 changes: 1 addition & 1 deletion python/cudf/cudf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import rmm

from cudf.api.types import dtype
from cudf import core, datasets, testing
from cudf import api, core, datasets, testing
from cudf._version import get_versions
from cudf.api.extensions import (
register_dataframe_accessor,
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/binaryop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from cudf._lib.cpp.scalar.scalar cimport scalar
from cudf._lib.cpp.types cimport data_type, type_id
from cudf._lib.types cimport dtype_to_data_type, underlying_type_t_type_id

from cudf.utils.dtypes import is_scalar, is_string_dtype
from cudf.api.types import is_scalar, is_string_dtype

cimport cudf._lib.cpp.binaryop as cpp_binaryop
from cudf._lib.cpp.binaryop cimport binary_operator
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import rmm

import cudf
import cudf._lib as libcudfxx
from cudf.core.buffer import Buffer
from cudf.utils.dtypes import (
from cudf.api.types import (
is_categorical_dtype,
is_decimal_dtype,
is_list_dtype,
is_struct_dtype,
)
from cudf.core.buffer import Buffer

from cpython.buffer cimport PyObject_CheckBuffer
from libc.stdint cimport uintptr_t
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/csv.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ cdef csv_reader_options make_csv_reader_options(
csv_reader_options_c.set_dtypes(c_dtypes_map)
csv_reader_options_c.set_parse_hex(c_hex_col_names)
elif (
cudf.utils.dtypes.is_scalar(dtype) or
cudf.api.types.is_scalar(dtype) or
isinstance(dtype, (
np.dtype, pd.core.dtypes.dtypes.ExtensionDtype, type
))
Expand Down Expand Up @@ -520,7 +520,7 @@ cdef data_type _get_cudf_data_type_from_dtype(object dtype) except +:
# TODO: Remove this Error message once the
# following issue is fixed:
# https://github.com/rapidsai/cudf/issues/3960
if cudf.utils.dtypes.is_categorical_dtype(dtype):
if cudf.api.types.is_categorical_dtype(dtype):
raise NotImplementedError(
"CategoricalDtype as dtype is not yet "
"supported in CSV reader"
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from pandas.core.groupby.groupby import DataError

import rmm

from cudf.utils.dtypes import (
from cudf.api.types import (
is_categorical_dtype,
is_decimal_dtype,
is_interval_dtype,
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/io/utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import io
import os

import cudf
from cudf.utils.dtypes import is_struct_dtype
from cudf.api.types import is_struct_dtype


# Converts the Python source input to libcudf++ IO source_info
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/json.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ cpdef read_json(object filepaths_or_buffers,
column_names=column_names)

cdef data_type _get_cudf_data_type_from_dtype(object dtype) except +:
if cudf.utils.dtypes.is_categorical_dtype(dtype):
if cudf.api.types.is_categorical_dtype(dtype):
raise NotImplementedError(
"CategoricalDtype as dtype is not yet "
"supported in JSON reader"
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/parquet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ except ImportError:
import numpy as np
from cython.operator import dereference

from cudf.utils.dtypes import (
from cudf.api.types import (
is_categorical_dtype,
is_decimal_dtype,
is_list_dtype,
is_struct_dtype,
np_to_pa_dtype,
)
from cudf.utils.dtypes import np_to_pa_dtype

from cudf._lib.utils cimport data_from_unique_ptr, get_column_names

Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/_lib/reduce.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright (c) 2020-2021, NVIDIA CORPORATION.

import cudf
from cudf.utils.dtypes import is_decimal_dtype
from cudf.api.types import is_decimal_dtype
from cudf.core.dtypes import Decimal64Dtype

from cudf._lib.column cimport Column
from cudf._lib.cpp.column.column cimport column
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/replace.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move

from cudf.utils.dtypes import is_scalar
from cudf.api.types import is_scalar

from cudf._lib.column cimport Column

Expand Down
2 changes: 0 additions & 2 deletions python/cudf/cudf/_lib/scalar.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ from cudf._lib.cpp.wrappers.timestamps cimport (
)
from cudf._lib.utils cimport data_from_table_view

import cudf


cdef class DeviceScalar:

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/transpose.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2020, NVIDIA CORPORATION.

import cudf
from cudf.utils.dtypes import is_categorical_dtype
from cudf.api.types import is_categorical_dtype

from libcpp.memory cimport unique_ptr
from libcpp.pair cimport pair
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/unary.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from enum import IntEnum

from cudf.utils.dtypes import is_decimal_dtype
from cudf.api.types import is_decimal_dtype

from libcpp cimport bool
from libcpp.memory cimport unique_ptr
Expand Down
5 changes: 2 additions & 3 deletions python/cudf/cudf/_lib/utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ try:
except ImportError:
import json

from cudf.utils.dtypes import (
from cudf.api.types import (
is_categorical_dtype,
is_decimal_dtype,
is_list_dtype,
is_struct_dtype,
np_dtypes_to_pandas_dtypes,
np_to_pa_dtype,
)
from cudf.utils.dtypes import np_dtypes_to_pandas_dtypes, np_to_pa_dtype

PARQUET_META_TYPE_MAP = {
str(cudf_dtype): str(pandas_dtype)
Expand Down
4 changes: 1 addition & 3 deletions python/cudf/cudf/core/_base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

import cudf
from cudf._typing import DtypeObj
from cudf.api.types import is_dtype_equal, is_integer
from cudf.api.types import is_dtype_equal, is_integer, is_list_like, is_scalar
from cudf.core.abc import Serializable
from cudf.core.column import ColumnBase, column
from cudf.core.column_accessor import ColumnAccessor
from cudf.utils import ioutils
from cudf.utils.dtypes import (
is_list_like,
is_mixed_with_object_dtype,
is_scalar,
numeric_normalize_types,
)
from cudf.utils.utils import cached_property
Expand Down
28 changes: 13 additions & 15 deletions python/cudf/cudf/core/_internals/where.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def _check_and_cast_columns_with_other(
Returns type-casted column `source_col` & scalar `other_scalar`
based on `inplace` parameter.
"""
if cudf.utils.dtypes.is_categorical_dtype(source_col.dtype):
if cudf.api.types.is_categorical_dtype(source_col.dtype):
return source_col, other

if cudf.utils.dtypes.is_scalar(other):
if cudf.api.types.is_scalar(other):
device_obj = _normalize_scalars(source_col, other)
else:
device_obj = other
Expand All @@ -66,10 +66,8 @@ def _check_and_cast_columns_with_other(
return source_col, device_obj.astype(source_col.dtype)
else:
if (
cudf.utils.dtypes.is_scalar(other)
and cudf.utils.dtypes._is_non_decimal_numeric_dtype(
source_col.dtype
)
cudf.api.types.is_scalar(other)
and cudf.api.types._is_non_decimal_numeric_dtype(source_col.dtype)
and cudf.utils.dtypes._can_cast(other, source_col.dtype)
):
common_dtype = source_col.dtype
Expand All @@ -82,11 +80,11 @@ def _check_and_cast_columns_with_other(
[
source_col.dtype,
np.min_scalar_type(other)
if cudf.utils.dtypes.is_scalar(other)
if cudf.api.types.is_scalar(other)
else other.dtype,
]
)
if cudf.utils.dtypes.is_scalar(device_obj):
if cudf.api.types.is_scalar(device_obj):
device_obj = cudf.Scalar(other, dtype=common_dtype)
else:
device_obj = device_obj.astype(common_dtype)
Expand Down Expand Up @@ -132,17 +130,17 @@ def _normalize_columns_and_scalars_type(
other_df._data[self_col] = other_col
return source_df, other_df

elif isinstance(
frame, (Series, Index)
) and not cudf.utils.dtypes.is_scalar(other):
elif isinstance(frame, (Series, Index)) and not cudf.api.types.is_scalar(
other
):
other = cudf.core.column.as_column(other)
input_col = frame._data[frame.name]
return _check_and_cast_columns_with_other(
source_col=input_col, other=other, inplace=inplace
)
else:
# Handles scalar or list/array like scalars
if isinstance(frame, (Series, Index)) and cudf.utils.dtypes.is_scalar(
if isinstance(frame, (Series, Index)) and cudf.api.types.is_scalar(
other
):
input_col = frame._data[frame.name]
Expand All @@ -162,7 +160,7 @@ def _normalize_columns_and_scalars_type(
) = _check_and_cast_columns_with_other(
source_col=source_df._data[col_name],
other=other
if cudf.utils.dtypes.is_scalar(other)
if cudf.api.types.is_scalar(other)
else other[i],
inplace=inplace,
)
Expand Down Expand Up @@ -284,7 +282,7 @@ def where(
other_column = others[i]
if column_name in cond._data:
if isinstance(input_col, cudf.core.column.CategoricalColumn):
if cudf.utils.dtypes.is_scalar(other_column):
if cudf.api.types.is_scalar(other_column):
try:
other_column = input_col._encode(other_column)
except ValueError:
Expand Down Expand Up @@ -346,7 +344,7 @@ def where(
)

if isinstance(input_col, cudf.core.column.CategoricalColumn):
if cudf.utils.dtypes.is_scalar(other):
if cudf.api.types.is_scalar(other):
try:
other = input_col._encode(other)
except ValueError:
Expand Down
7 changes: 3 additions & 4 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
from cudf import _lib as libcudf
from cudf._lib.transform import bools_to_mask
from cudf._typing import ColumnLike, Dtype, ScalarLike
from cudf.api.types import is_categorical_dtype, is_interval_dtype
from cudf.core.buffer import Buffer
from cudf.core.column import column
from cudf.core.column.methods import ColumnMethods
from cudf.core.dtypes import CategoricalDtype
from cudf.utils.dtypes import (
is_categorical_dtype,
is_interval_dtype,
is_mixed_with_object_dtype,
min_signed_type,
min_unsigned_type,
Expand Down Expand Up @@ -802,7 +801,7 @@ def unary_operator(self, unaryop: str):
)

def __setitem__(self, key, value):
if cudf.utils.dtypes.is_scalar(
if cudf.api.types.is_scalar(
value
) and cudf._lib.scalar._is_null_host_scalar(value):
to_add_categories = 0
Expand All @@ -817,7 +816,7 @@ def __setitem__(self, key, value):
"category, set the categories first"
)

if cudf.utils.dtypes.is_scalar(value):
if cudf.api.types.is_scalar(value):
value = self._encode(value) if value is not None else value
else:
value = cudf.core.column.as_column(value).astype(self.dtype)
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import cudf
from cudf import _lib as libcudf
from cudf._typing import DatetimeLikeScalar, Dtype, DtypeObj, ScalarLike
from cudf.api.types import is_scalar
from cudf.core._compat import PANDAS_GE_120
from cudf.core.buffer import Buffer
from cudf.core.column import (
Expand All @@ -24,7 +25,6 @@
column_empty_like,
string,
)
from cudf.utils.dtypes import is_scalar
from cudf.utils.utils import _fillna_natwise

if PANDAS_GE_120:
Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
from_decimal as cpp_from_decimal,
)
from cudf._typing import Dtype
from cudf.api.types import is_integer_dtype
from cudf.api.types import is_integer_dtype, is_scalar
from cudf.core.buffer import Buffer
from cudf.core.column import ColumnBase, as_column
from cudf.core.dtypes import Decimal32Dtype, Decimal64Dtype
from cudf.utils.dtypes import is_scalar
from cudf.utils.utils import pa_mask_buffer_to_mask

from .numerical_base import NumericalBaseColumn
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pyarrow as pa

import cudf
from cudf.api.types import is_interval_dtype
from cudf.core.column import StructColumn
from cudf.core.dtypes import IntervalDtype
from cudf.utils.dtypes import is_interval_dtype


class IntervalColumn(StructColumn):
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
)
from cudf._lib.table import Table
from cudf._typing import BinaryOperand, ColumnLike, Dtype, ScalarLike
from cudf.api.types import _is_non_decimal_numeric_dtype, is_list_dtype
from cudf.core.buffer import Buffer
from cudf.core.column import ColumnBase, as_column, column
from cudf.core.column.methods import ColumnMethods, ParentType
from cudf.core.dtypes import ListDtype
from cudf.utils.dtypes import _is_non_decimal_numeric_dtype, is_list_dtype


class ListColumn(ColumnBase):
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/numerical_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def skew(self, skipna: bool = None) -> ScalarLike:
def quantile(
self, q: Union[float, Sequence[float]], interpolation: str, exact: bool
) -> NumericalBaseColumn:
if isinstance(q, Number) or cudf.utils.dtypes.is_list_like(q):
if isinstance(q, Number) or cudf.api.types.is_list_like(q):
np_array_q = np.asarray(q)
if np.logical_or(np_array_q < 0, np_array_q > 1).any():
raise ValueError(
Expand Down
14 changes: 7 additions & 7 deletions python/cudf/cudf/core/column/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
from cudf import _lib as libcudf
from cudf._lib import string_casting as str_cast, strings as libstrings
from cudf._lib.column import Column
from cudf.core.buffer import Buffer
from cudf.core.column import column, datetime
from cudf.core.column.methods import ColumnMethods, ParentType
from cudf.utils import utils
from cudf.utils.docutils import copy_docstring
from cudf.utils.dtypes import (
can_convert_to_column,
from cudf.api.types import (
is_integer,
is_list_dtype,
is_scalar,
is_string_dtype,
)
from cudf.core.buffer import Buffer
from cudf.core.column import column, datetime
from cudf.core.column.methods import ColumnMethods, ParentType
from cudf.utils import utils
from cudf.utils.docutils import copy_docstring
from cudf.utils.dtypes import can_convert_to_column


def str_to_boolean(column: StringColumn):
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import cudf
from cudf._typing import Dtype
from cudf.api.types import is_struct_dtype
from cudf.core.column import ColumnBase, build_struct_column
from cudf.core.column.methods import ColumnMethods
from cudf.core.dtypes import StructDtype
from cudf.utils.dtypes import is_struct_dtype


class StructColumn(ColumnBase):
Expand Down

0 comments on commit 945b28b

Please sign in to comment.