diff --git a/python/cudf/cudf/core/frame.py b/python/cudf/cudf/core/frame.py index 25552009444..f59954aaf08 100644 --- a/python/cudf/cudf/core/frame.py +++ b/python/cudf/cudf/core/frame.py @@ -28,8 +28,8 @@ from cudf.utils.dtypes import ( is_categorical_dtype, is_column_like, - is_numerical_dtype, is_decimal_dtype, + is_numerical_dtype, is_scalar, min_scalar_type, ) @@ -3364,6 +3364,10 @@ def __bool__(self): "a.empty, a.bool(), a.item(), a.any() or a.all()." ) + @property + def _num_columns(self): + return 1 + @property def _column(self): return self._data[self.name] @@ -3529,6 +3533,79 @@ def to_arrow(self): """ return self._column.to_arrow() + @property + def is_unique(self): + """Return boolean if values in the object are unique. + + Returns + ------- + bool + """ + return self._column.is_unique + + @property + def is_monotonic(self): + """Return boolean if values in the object are monotonic_increasing. + + This property is an alias for :attr:`is_monotonic_increasing`. + + Returns + ------- + bool + """ + return self.is_monotonic_increasing + + @property + def is_monotonic_increasing(self): + """Return boolean if values in the object are monotonic_increasing. + + Returns + ------- + bool + """ + return self._column.is_monotonic_increasing + + @property + def is_monotonic_decreasing(self): + """Return boolean if values in the object are monotonic_decreasing. + + Returns + ------- + bool + """ + return self._column.is_monotonic_decreasing + + @property + def __cuda_array_interface__(self): + return self._column.__cuda_array_interface__ + + def factorize(self, na_sentinel=-1): + """Encode the input values as integer labels + + Parameters + ---------- + na_sentinel : number + Value to indicate missing category. + + Returns + -------- + (labels, cats) : (cupy.ndarray, cupy.ndarray or Index) + - *labels* contains the encoded values + - *cats* contains the categories in order that the N-th + item corresponds to the (N-1) code. + + Examples + -------- + >>> import cudf + >>> s = cudf.Series(['a', 'a', 'c']) + >>> codes, uniques = s.factorize() + >>> codes + array([0, 0, 1], dtype=int8) + >>> uniques + StringIndex(['a' 'c'], dtype='object') + """ + return cudf.core.algorithms.factorize(self, na_sentinel=na_sentinel) + @property def _copy_construct_defaults(self): """A default dictionary of kwargs to be used for copy construction.""" diff --git a/python/cudf/cudf/core/index.py b/python/cudf/cudf/core/index.py index 2846dc241db..94ddeb72028 100644 --- a/python/cudf/cudf/core/index.py +++ b/python/cudf/cudf/core/index.py @@ -335,17 +335,6 @@ def _clean_nulls_from_index(self): else: return self - def factorize(self, na_sentinel=-1): - """ - Encode the input values as integer labels - - See Also - -------- - cudf.core.series.Series.factorize : Encode the input values of Series. - - """ - return cudf.core.algorithms.factorize(self, na_sentinel=na_sentinel) - @property def nlevels(self): """ @@ -1143,59 +1132,6 @@ def to_series(self, index=None, name=None): name=self.name if name is None else name, ) - @property - def is_unique(self): - """ - Return if the index has unique values. - """ - raise (NotImplementedError) - - @property - def is_monotonic(self): - """ - Alias for is_monotonic_increasing. - """ - return self.is_monotonic_increasing - - @property - def is_monotonic_increasing(self): - """ - Return if the index is monotonic increasing - (only equal or increasing) values. - """ - return self._values.is_monotonic_increasing - - @property - def is_monotonic_decreasing(self): - """ - Return if the index is monotonic decreasing - (only equal or decreasing) values. - """ - return self._values.is_monotonic_decreasing - - @property - def empty(self): - """ - Indicator whether Index is empty. - - True if Index is entirely empty (no items). - - Returns - ------- - out : bool - If Index is empty, return True, if not return False. - - Examples - -------- - >>> import cudf - >>> index = cudf.Index([]) - >>> index - Float64Index([], dtype='float64') - >>> index.empty - True - """ - return not self.size - def get_slice_bound(self, label, side, kind): """ Calculate slice bound that corresponds to given label. @@ -1277,9 +1213,7 @@ def isin(self, values): array([ True, False, False]) """ - result = self.to_series().isin(values).values - - return result + return self._values.isin(values).values def where(self, cond, other=None): """ @@ -1311,10 +1245,6 @@ def where(self, cond, other=None): """ return super().where(cond=cond, other=other) - @property - def __cuda_array_interface__(self): - raise (NotImplementedError) - def memory_usage(self, deep=False): """ Memory usage of the values. @@ -1507,10 +1437,6 @@ def step(self): """ return self._step - @property - def _num_columns(self): - return 1 - @property def _num_rows(self): return len(self) @@ -1772,10 +1698,6 @@ def get_slice_bound(self, label, side, kind=None): pos = search_range(start, stop, label, step, side=side) return pos - @property - def __cuda_array_interface__(self): - return self._values.__cuda_array_interface__ - def memory_usage(self, **kwargs): return 0 @@ -1837,7 +1759,7 @@ def _initialize(self, values, **kwargs): @property def _values(self): - return next(iter(self._data.columns)) + return self._column def copy(self, name=None, deep=False, dtype=None, names=None): """ @@ -1989,20 +1911,9 @@ def find_label_range(self, first, last): end += 1 return begin, end - @property - def is_unique(self): - """ - Return if the index has unique values. - """ - return self._values.is_unique - def get_slice_bound(self, label, side, kind): return self._values.get_slice_bound(label, side, kind) - @property - def __cuda_array_interface__(self): - return self._values.__cuda_array_interface__ - class NumericIndex(GenericIndex): """Immutable, ordered and sliceable sequence of labels. diff --git a/python/cudf/cudf/core/multiindex.py b/python/cudf/cudf/core/multiindex.py index ca029198e52..e0a895f28cc 100644 --- a/python/cudf/cudf/core/multiindex.py +++ b/python/cudf/cudf/core/multiindex.py @@ -204,6 +204,11 @@ def names(self, value): ) self._names = pd.core.indexes.frozen.FrozenList(value) + @property + def _num_columns(self): + # MultiIndex is not a single-columned frame. + return super(SingleColumnFrame, self)._num_columns + def rename(self, names, inplace=False): """ Alter MultiIndex level names diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index 7b1e6454394..d9685521c63 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -3860,32 +3860,6 @@ def _return_sentinel_series(): return codes._copy_construct(name=None, index=self.index) - def factorize(self, na_sentinel=-1): - """Encode the input values as integer labels - - Parameters - ---------- - na_sentinel : number - Value to indicate missing category. - - Returns - -------- - (labels, cats) : (cupy.ndarray, cupy.ndarray or Index) - - *labels* contains the encoded values - - *cats* contains the categories in order that the N-th - item corresponds to the (N-1) code. - - Examples - -------- - >>> import cudf - >>> s = cudf.Series(['a', 'a', 'c']) - >>> codes - array([0, 0, 1], dtype=int8) - >>> uniques - StringIndex(['a' 'c'], dtype='object') - """ - return cudf.core.algorithms.factorize(self, na_sentinel=na_sentinel) - # UDF related def applymap(self, udf, out_dtype=None): @@ -4253,60 +4227,7 @@ def product( skipna=skipna, dtype=dtype, min_count=min_count ) - def prod( - self, - axis=None, - skipna=None, - dtype=None, - level=None, - numeric_only=None, - min_count=0, - **kwargs, - ): - """ - Return product of the values in the series - - Parameters - ---------- - - skipna : bool, default True - Exclude NA/null values when computing the result. - - dtype : data type - Data type to cast the result to. - - min_count : int, default 0 - The required number of valid values to perform the operation. - If fewer than min_count non-NA values are present the result - will be NA. - - The default being 0. This means the sum of an all-NA or empty - Series is 0, and the product of an all-NA or empty Series is 1. - - Returns - ------- - scalar - - Notes - ----- - Parameters currently not supported are `axis`, `level`, `numeric_only`. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([1, 5, 2, 4, 3]) - >>> ser.prod() - 120 - """ - return self.product( - axis=axis, - skipna=skipna, - dtype=dtype, - level=level, - numeric_only=numeric_only, - min_count=min_count, - **kwargs, - ) + prod = product def cummin(self, axis=None, skipna=True, *args, **kwargs): """ @@ -5934,54 +5855,6 @@ def rename(self, index=None, copy=True): return out.copy(deep=copy) - @property - def is_unique(self): - """ - Return boolean if values in the object are unique. - - Returns - ------- - out : bool - """ - return self._column.is_unique - - @property - def is_monotonic(self): - """ - Return boolean if values in the object are monotonic_increasing. - - Returns - ------- - out : bool - """ - return self._column.is_monotonic_increasing - - @property - def is_monotonic_increasing(self): - """ - Return boolean if values in the object are monotonic_increasing. - - Returns - ------- - out : bool - """ - return self._column.is_monotonic_increasing - - @property - def is_monotonic_decreasing(self): - """ - Return boolean if values in the object are monotonic_decreasing. - - Returns - ------- - out : bool - """ - return self._column.is_monotonic_decreasing - - @property - def __cuda_array_interface__(self): - return self._column.__cuda_array_interface__ - def _align_to_index( self, index, how="outer", sort=True, allow_non_unique=False ):