Skip to content

Commit

Permalink
rework imports
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-b-miller committed May 4, 2022
1 parent 6128e0d commit a0fd101
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion python/cudf/cudf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
register_series_accessor,
)
from cudf.core.scalar import (
NA,
Scalar,
)
from cudf.core.index import (
Expand All @@ -45,6 +44,7 @@
)
from cudf.core.dataframe import DataFrame, from_pandas, merge, from_dataframe
from cudf.core.series import Series
from cudf.core.missing import NA
from cudf.core.multiindex import MultiIndex
from cudf.core.cut import cut
from cudf.core.algorithms import factorize
Expand Down
7 changes: 7 additions & 0 deletions python/cudf/cudf/core/missing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2018-2022, NVIDIA CORPORATION.


# Pandas NAType enforces a single instance exists at a time
# instantiating this class will yield the existing instance
# of pandas._libs.missing.NAType, id(cudf.NA) == id(pd.NA).
from pandas import NA # noqa: F401
40 changes: 14 additions & 26 deletions python/cudf/cudf/core/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

import numpy as np
import pyarrow as pa
from pandas._libs.missing import NAType as pd_NAType

import cudf
from cudf.core.column.column import ColumnBase
from cudf.api.types import is_scalar
from cudf.core.dtypes import ListDtype, StructDtype
from cudf.core.index import BaseIndex
from cudf.core.missing import NA
from cudf.core.mixins import BinaryOperand
from cudf.core.series import Series
from cudf.utils.dtypes import (
get_allowed_combinations_for_operator,
to_cudf_compatible_scalar,
Expand Down Expand Up @@ -273,19 +271,19 @@ def _binop_result_dtype_or_error(self, other, op):
return cudf.dtype(out_dtype)

def _binaryop(self, other, op: str):
if isinstance(other, (ColumnBase, Series, BaseIndex, np.ndarray)):
# dispatch to column implementation
return NotImplemented
other = to_cudf_compatible_scalar(other)
out_dtype = self._binop_result_dtype_or_error(other, op)
valid = self.is_valid and (
isinstance(other, np.generic) or other.is_valid
)
if not valid:
return Scalar(None, dtype=out_dtype)
if is_scalar(other):
other = to_cudf_compatible_scalar(other)
out_dtype = self._binop_result_dtype_or_error(other, op)
valid = self.is_valid and (
isinstance(other, np.generic) or other.is_valid
)
if not valid:
return Scalar(None, dtype=out_dtype)
else:
result = self._dispatch_scalar_binop(other, op)
return Scalar(result, dtype=out_dtype)
else:
result = self._dispatch_scalar_binop(other, op)
return Scalar(result, dtype=out_dtype)
return NotImplemented

def _dispatch_scalar_binop(self, other, op):
if isinstance(other, Scalar):
Expand Down Expand Up @@ -323,13 +321,3 @@ def _dispatch_scalar_unaop(self, op):

def astype(self, dtype):
return Scalar(self.value, dtype)


class _NAType(pd_NAType):
# Pandas NAType enforces a single instance exists at a time
# instantiating this class will yield the existing instance
# of pandas._libs.missing.NAType, id(cudf.NA) == id(pd.NA).
pass


NA = _NAType()

0 comments on commit a0fd101

Please sign in to comment.