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

Refactor DataFrame tests. #10204

Merged
merged 1 commit into from
Feb 3, 2022
Merged
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
79 changes: 37 additions & 42 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,15 @@ def test_series_init_none():
sr1 = cudf.Series()
got = sr1.to_string()

expect = sr1.to_pandas().__repr__()
# values should match despite whitespace difference
assert got.split() == expect.split()
expect = repr(sr1.to_pandas())
assert got == expect

# 2: Using `None` as an initializer
sr2 = cudf.Series(None)
got = sr2.to_string()

expect = sr2.to_pandas().__repr__()
# values should match despite whitespace difference
assert got.split() == expect.split()
expect = repr(sr2.to_pandas())
assert got == expect


def test_dataframe_basic():
Expand Down Expand Up @@ -843,31 +841,29 @@ def test_dataframe_to_string_with_masked_data():
def test_dataframe_to_string_wide(monkeypatch):
monkeypatch.setenv("COLUMNS", "79")
# Test basic
df = cudf.DataFrame()
for i in range(100):
df["a{}".format(i)] = list(range(3))
pd.options.display.max_columns = 0
got = df.to_string()
df = cudf.DataFrame({f"a{i}": [0, 1, 2] for i in range(100)})
with pd.option_context("display.max_columns", 0):
got = df.to_string()

expect = """
a0 a1 a2 a3 a4 a5 a6 a7 ... a92 a93 a94 a95 a96 a97 a98 a99
0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 ... 2 2 2 2 2 2 2 2
[3 rows x 100 columns]
"""
# values should match despite whitespace difference
assert got.split() == expect.split()
expect = textwrap.dedent(
"""\
a0 a1 a2 a3 a4 a5 a6 a7 ... a92 a93 a94 a95 a96 a97 a98 a99
0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 ... 2 2 2 2 2 2 2 2

[3 rows x 100 columns]""" # noqa: E501
)
assert got == expect


def test_dataframe_empty_to_string():
# Test for printing empty dataframe
df = cudf.DataFrame()
got = df.to_string()

expect = "Empty DataFrame\nColumns: []\nIndex: []\n"
# values should match despite whitespace difference
assert got.split() == expect.split()
expect = "Empty DataFrame\nColumns: []\nIndex: []"
assert got == expect


def test_dataframe_emptycolumns_to_string():
Expand All @@ -877,9 +873,8 @@ def test_dataframe_emptycolumns_to_string():
df["b"] = []
got = df.to_string()

expect = "Empty DataFrame\nColumns: [a, b]\nIndex: []\n"
# values should match despite whitespace difference
assert got.split() == expect.split()
expect = "Empty DataFrame\nColumns: [a, b]\nIndex: []"
assert got == expect


def test_dataframe_copy():
Expand All @@ -890,14 +885,14 @@ def test_dataframe_copy():
df2["b"] = [4, 5, 6]
got = df.to_string()

expect = """
a
0 1
1 2
2 3
"""
# values should match despite whitespace difference
assert got.split() == expect.split()
expect = textwrap.dedent(
"""\
a
0 1
1 2
2 3"""
)
assert got == expect


def test_dataframe_copy_shallow():
Expand All @@ -908,14 +903,14 @@ def test_dataframe_copy_shallow():
df2["b"] = [4, 2, 3]
got = df.to_string()

expect = """
a
0 1
1 2
2 3
"""
# values should match despite whitespace difference
assert got.split() == expect.split()
expect = textwrap.dedent(
"""\
a
0 1
1 2
2 3"""
)
assert got == expect


def test_dataframe_dtypes():
Expand Down