-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(pyspark): add tests to read split CSV outputs
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import pandas.testing as tm | ||
import pytest | ||
|
||
pytest.importorskip("pyspark") | ||
|
||
from pyspark.sql import SparkSession # noqa: E402 | ||
|
||
from ibis.backends.pyspark.datatypes import PySparkSchema # noqa: E402 | ||
|
||
|
||
@pytest.fixture | ||
def awards_players(con): | ||
return con.table("awards_players") | ||
|
||
|
||
def test_table_to_csv(tmp_path, awards_players): | ||
outcsv = tmp_path / "out.csv" | ||
|
||
# avoid pandas NaNonense | ||
columns = ["playerID", "awardID", "yearID", "lgID"] | ||
awards_players = awards_players.select(columns) | ||
|
||
awards_players.to_csv(outcsv) | ||
|
||
spark = SparkSession.builder.getOrCreate() | ||
df = spark.read.csv( | ||
str(outcsv), schema=PySparkSchema.from_ibis(awards_players.schema()) | ||
).toPandas() | ||
|
||
tm.assert_frame_equal( | ||
awards_players.to_pandas().sort_values(by=columns).reset_index(drop=True), | ||
df.sort_values(by=columns).reset_index(drop=True), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters