Skip to content

Commit

Permalink
Added more testcases and changed how equality is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneding committed May 21, 2021
1 parent 15ced45 commit c06be48
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def _is_homogeneous(self):
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)
first_type = self._data.columns[0].dtype.name
return all(x.dtype.name == first_type for x in self._data.columns)

@property
def empty(self):
Expand Down
56 changes: 55 additions & 1 deletion python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8582,16 +8582,70 @@ def test_dataframe_init_from_series(data, columns, index):


@pytest.mark.parametrize(
"data,expected",
"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),
({"a": [True, False, False]}, True),
({"a": [[1, 2], [3, 4]]}, True),
({"a": [[1, 2], [3, 4]], "b": ["a", "b"]}, False),
({"a": [{"c": 5}, {"e": 5}], "b": [{"c": 5}, {"g": 7}]}, True),
({}, True),
],
)
def test_is_homogeneous(data, expected):
actual = cudf.DataFrame(data)._is_homogeneous

assert actual == expected


@pytest.mark.parametrize(
"data, indexes, expected",
[
(
{"a": [1, 2, 3, 4], "b": [5, 6, 7, 8], "c": [1.2, 1, 2, 3]},
["a", "b"],
True,
),
(
{
"a": [1, 2, 3, 4],
"b": [5, 6, 7, 8],
"c": [1.2, 1, 2, 3],
"d": ["hello", "world", "cudf", "rapids"],
},
["a", "b"],
False,
),
(
{
"a": ["a", "b", "c"],
"b": [4, 5, 6],
"c": [7, 8, 9],
"d": [1, 2, 3],
},
["a", "b"],
True,
),
],
)
def test_is_homogeneous_multiindex(data, indexes, expected):
test_dataframe = cudf.DataFrame(data).set_index(indexes)
actual = cudf.DataFrame(test_dataframe)._is_homogeneous

assert actual == expected


"""
({"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),
({"a": [True, False, False]}, True),
({"a": [[1,2],[3,4]]}, True),
({'a': [[1,2], [3,4]], 'b': ["a", "b"]}, False),
({'a': [{'c':5} , {'e': 5}], 'b': [{'c':5} , {'g': 7}]}, True),
({}, True),
"""

0 comments on commit c06be48

Please sign in to comment.