Skip to content

Commit

Permalink
test(pyspark): add tests to read split CSV outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
deepyaman committed Apr 3, 2024
1 parent 68ebcdd commit 0960a68
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions ibis/backends/pyspark/tests/test_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import annotations

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L1

Added line #L1 was not covered by tests

import pandas.testing as tm
import pytest

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L3-L4

Added lines #L3 - L4 were not covered by tests

pytest.importorskip("pyspark")

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L6

Added line #L6 was not covered by tests

from pyspark.sql import SparkSession # noqa: E402

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L8 was not covered by tests

from ibis.backends.pyspark.datatypes import PySparkSchema # noqa: E402

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L10

Added line #L10 was not covered by tests


@pytest.fixture

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L13

Added line #L13 was not covered by tests
def awards_players(con):
return con.table("awards_players")

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L15

Added line #L15 was not covered by tests


def test_table_to_csv(tmp_path, awards_players):
outcsv = tmp_path / "out.csv"

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L18-L19

Added lines #L18 - L19 were not covered by tests

# avoid pandas NaNonense
columns = ["playerID", "awardID", "yearID", "lgID"]
awards_players = awards_players.select(columns)

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L22-L23

Added lines #L22 - L23 were not covered by tests

awards_players.to_csv(outcsv)

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L25

Added line #L25 was not covered by tests

spark = SparkSession.builder.getOrCreate()
df = spark.read.csv(

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L27-L28

Added lines #L27 - L28 were not covered by tests
str(outcsv), schema=PySparkSchema.from_ibis(awards_players.schema())
).toPandas()

tm.assert_frame_equal(

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

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_export.py#L32

Added line #L32 was not covered by tests
awards_players.to_pandas().sort_values(by=columns).reset_index(drop=True),
df.sort_values(by=columns).reset_index(drop=True),
)
2 changes: 1 addition & 1 deletion ibis/backends/pyspark/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import ibis

pyspark = pytest.importorskip("pyspark")
pytest.importorskip("pyspark")

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L8 was not covered by tests

import pyspark.sql.functions as F # noqa: E402
from pyspark.sql.window import Window # noqa: E402
Expand Down

0 comments on commit 0960a68

Please sign in to comment.