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

Various internal MultiIndex improvements #9243

Merged
merged 19 commits into from
Sep 22, 2021
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
37 changes: 37 additions & 0 deletions python/cudf/cudf/core/_base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def _values(self) -> ColumnBase:
def copy(self, deep: bool = True) -> BaseIndex:
raise NotImplementedError

@property
def size(self):
# The size of an index is always its length irrespective of dimension.
return len(self)

@property
def values(self):
return self._values.values
Expand Down Expand Up @@ -162,6 +167,38 @@ def _clean_nulls_from_index(self):
else:
return self

@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):
vyasr marked this conversation as resolved.
Show resolved Hide resolved
"""Return boolean if values in the object are monotonically increasing.

Returns
-------
bool
"""
raise NotImplementedError

@property
def is_monotonic_decreasing(self):
"""Return boolean if values in the object are monotonically decreasing.

Returns
-------
bool
"""
raise NotImplementedError

@property
def nlevels(self):
"""
Expand Down
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/column/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ def cat(self, others=None, sep=None, na_rep=None):

if len(data) == 1 and data.null_count == 1:
data = [""]
out = self._return_or_inplace(data)
# We only want to keep the index if we are adding something to each
# row, not if we are joining all the rows into a single string.
out = self._return_or_inplace(data, retain_index=others is not None)
if len(out) == 1 and others is None:
if isinstance(out, cudf.Series):
out = out.iloc[0]
Expand Down
12 changes: 0 additions & 12 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,6 @@ def dtypes(self):
data=[x.dtype for x in self._data.columns], index=self._data.names,
)

@property
def shape(self):
"""Returns a tuple representing the dimensionality of the DataFrame.
"""
return self._num_rows, self._num_columns

@property
def ndim(self):
"""Dimension of the data. DataFrame ndim is always 2.
Expand Down Expand Up @@ -938,12 +932,6 @@ def memory_usage(self, index=True, deep=False):
sizes.append(self.index.memory_usage(deep=deep))
return Series(sizes, index=ind)

def __len__(self):
"""
Returns the number of rows
"""
return len(self.index)

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
import cudf

Expand Down
20 changes: 14 additions & 6 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ def size(self):
"""
return self._num_columns * self._num_rows

@property
def shape(self):
"""Returns a tuple representing the dimensionality of the DataFrame."""
return self._num_rows, self._num_columns

@property
def _is_homogeneous(self):
# make sure that the dataframe has columns
Expand Down Expand Up @@ -4458,6 +4463,12 @@ def to_string(self):
def __str__(self):
return self.to_string()

def __deepcopy__(self, memo):
return self.copy(deep=True)

def __copy__(self):
return self.copy(deep=False)

def head(self, n=5):
"""
Return the first `n` rows.
Expand Down Expand Up @@ -4726,9 +4737,6 @@ def __iter__(self):
"""
cudf.utils.utils.raise_iteration_error(obj=self)

def __len__(self):
return len(self._column)

def __bool__(self):
raise TypeError(
f"The truth value of a {type(self)} is ambiguous. Use "
Expand Down Expand Up @@ -4916,7 +4924,7 @@ def is_unique(self):

@property
def is_monotonic(self):
"""Return boolean if values in the object are monotonic_increasing.
"""Return boolean if values in the object are monotonically increasing.

This property is an alias for :attr:`is_monotonic_increasing`.

Expand All @@ -4928,7 +4936,7 @@ def is_monotonic(self):

@property
def is_monotonic_increasing(self):
"""Return boolean if values in the object are monotonic_increasing.
"""Return boolean if values in the object are monotonically increasing.

Returns
-------
Expand All @@ -4938,7 +4946,7 @@ def is_monotonic_increasing(self):

@property
def is_monotonic_decreasing(self):
"""Return boolean if values in the object are monotonic_decreasing.
"""Return boolean if values in the object are monotonically decreasing.

Returns
-------
Expand Down
19 changes: 0 additions & 19 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,6 @@ def dtype(self):
"""
return cudf.dtype(np.int64)

@property
def is_contiguous(self):
"""
Returns if the index is contiguous.
"""
return self._step == 1

@property
def size(self):
return len(self)

def find_label_range(self, first=None, last=None):
"""Find subrange in the ``RangeIndex``, marked by their positions, that
starts greater or equal to ``first`` and ends less or equal to ``last``
Expand Down Expand Up @@ -417,18 +406,10 @@ def is_unique(self):

@property
def is_monotonic_increasing(self):
"""
Return if the index is monotonic increasing
(only equal or increasing) values.
"""
return self._step > 0 or len(self) <= 1

@property
def is_monotonic_decreasing(self):
"""
Return if the index is monotonic decreasing
(only equal or decreasing) values.
"""
return self._step < 0 or len(self) <= 1

def get_slice_bound(self, label, side, kind=None):
Expand Down
Loading