Skip to content

Commit

Permalink
feature(pytest): Update testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jakepenzak committed Feb 15, 2025
1 parent b0a10aa commit 0aba430
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
15 changes: 11 additions & 4 deletions ibis/backends/pyspark/tests/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
import pytest
from pandas.testing import assert_frame_equal

Check warning on line 8 in ibis/backends/pyspark/tests/test_import_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_import_export.py#L8

Added line #L8 was not covered by tests

from ibis.backends.pyspark.datatypes import PySparkSchema

Expand Down Expand Up @@ -83,8 +84,11 @@ def test_to_parquet_read_parquet(con, tmp_path):

t_in = con.read_parquet(tmp_path / "out_np")

Check warning on line 85 in ibis/backends/pyspark/tests/test_import_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_import_export.py#L85

Added line #L85 was not covered by tests

assert t_out.to_pandas().shape == t_in.to_pandas().shape
assert sorted(t_out.columns) == sorted(t_in.columns)
cols = list(t_out.columns)
expected = t_out.to_pandas()[cols].sort_values(cols).reset_index(drop=True)
result = t_in.to_pandas()[cols].sort_values(cols).reset_index(drop=True)

Check warning on line 89 in ibis/backends/pyspark/tests/test_import_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_import_export.py#L87-L89

Added lines #L87 - L89 were not covered by tests

assert_frame_equal(expected, result)

Check warning on line 91 in ibis/backends/pyspark/tests/test_import_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_import_export.py#L91

Added line #L91 was not covered by tests

# Partitions
t_out = con.table("awards_players")

Check warning on line 94 in ibis/backends/pyspark/tests/test_import_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_import_export.py#L94

Added line #L94 was not covered by tests
Expand All @@ -99,5 +103,8 @@ def test_to_parquet_read_parquet(con, tmp_path):

t_in = con.read_parquet(tmp_path / "out_p")

Check warning on line 104 in ibis/backends/pyspark/tests/test_import_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_import_export.py#L104

Added line #L104 was not covered by tests

assert t_out.to_pandas().shape == t_in.to_pandas().shape
assert sorted(t_out.columns) == sorted(t_in.columns)
cols = list(t_out.columns)
expected = t_out.to_pandas()[cols].sort_values(cols).reset_index(drop=True)
result = t_in.to_pandas()[cols].sort_values(cols).reset_index(drop=True)

Check warning on line 108 in ibis/backends/pyspark/tests/test_import_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_import_export.py#L106-L108

Added lines #L106 - L108 were not covered by tests

assert_frame_equal(expected, result)

Check warning on line 110 in ibis/backends/pyspark/tests/test_import_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_import_export.py#L110

Added line #L110 was not covered by tests
32 changes: 25 additions & 7 deletions ibis/backends/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,30 @@ def test_table_to_parquet_writer_kwargs(version, tmp_path, backend, awards_playe
outparquet = tmp_path / "out.parquet"
awards_players.to_parquet(outparquet, version=version)

df = pd.read_parquet(outparquet)
if backend.name() == "pyspark":
# Pyspark will write more than one parquet file under outparquet as directory
parquet_files = sorted(outparquet.glob("*.parquet"))
df = (

Check warning on line 263 in ibis/backends/tests/test_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/tests/test_export.py#L262-L263

Added lines #L262 - L263 were not covered by tests
pd.concat(map(pd.read_parquet, parquet_files))
.sort_values(list(awards_players.columns))
.reset_index(drop=True)
)
result = (

Check warning on line 268 in ibis/backends/tests/test_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/tests/test_export.py#L268

Added line #L268 was not covered by tests
awards_players.to_pandas()
.sort_values(list(awards_players.columns))
.reset_index(drop=True)
)
backend.assert_frame_equal(result, df)

Check warning on line 273 in ibis/backends/tests/test_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/tests/test_export.py#L273

Added line #L273 was not covered by tests
else:
df = pd.read_parquet(outparquet)

backend.assert_frame_equal(
awards_players.to_pandas().fillna(pd.NA), df.fillna(pd.NA)
)
backend.assert_frame_equal(
awards_players.to_pandas().fillna(pd.NA), df.fillna(pd.NA)
)

md = pa.parquet.read_metadata(outparquet)
md = pa.parquet.read_metadata(outparquet)

assert md.format_version == version
assert md.format_version == version


@pytest.mark.notimpl(
Expand Down Expand Up @@ -333,7 +348,10 @@ def test_memtable_to_file(tmp_path, con, ftype, monkeypatch):

getattr(con, f"to_{ftype}")(memtable, outfile)

assert outfile.is_file()
if con.name == "pyspark" and ftype == "parquet":
assert outfile.is_dir()

Check warning on line 352 in ibis/backends/tests/test_export.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/tests/test_export.py#L352

Added line #L352 was not covered by tests
else:
assert outfile.is_file()


def test_table_to_csv(tmp_path, backend, awards_players):
Expand Down

0 comments on commit 0aba430

Please sign in to comment.