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

added _is_homogeneous property #8299

Merged
merged 5 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ def size(self):
"""
return self._num_columns * self._num_rows

@property
def _is_homogeneous(self):
# make sure that the dataframe has columns
if not self._data.columns:
return True

first_type = self._data.columns[0].dtype
return all(x.dtype == first_type for x in self._data.columns)

@property
def empty(self):
"""
Expand Down
16 changes: 16 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8579,3 +8579,19 @@ def test_dataframe_init_from_series(data, columns, index):
actual,
check_index_type=False if len(expected) == 0 else True,
)


@pytest.mark.parametrize(
"data,expected",
[
({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8], "c": [1.2, 1, 2, 3]}, False),
({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, True),
({"a": ["a", "b", "c"], "b": [4, 5, 6], "c": [7, 8, 9]}, False),
({"a": [True, False, False], "b": [False, False, True]}, True),
({}, True),
shaneding marked this conversation as resolved.
Show resolved Hide resolved
],
)
def test_is_homogeneous(data, expected):
actual = cudf.DataFrame(data)._is_homogeneous
shaneding marked this conversation as resolved.
Show resolved Hide resolved

assert actual == expected