-
Notifications
You must be signed in to change notification settings - Fork 119
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
chore: move pyspark tests into main test suite #1761
Merged
Merged
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3aac922
chore: move pyspark tests into main test suite
FBruzzesi 16162af
Merge branch 'main' into tests/pyspark-to-main
FBruzzesi 789a05c
delay call to pyspark constructor
FBruzzesi 2934687
xfail from_dict, from_numpy
FBruzzesi 582081e
Merge branch 'tests/pyspark-to-main' of https://github.com/narwhals-dβ¦
FBruzzesi 87d7ea5
WIP
FBruzzesi 71be730
very dynamic pyspark
FBruzzesi b605ed3
one more
FBruzzesi b5484fd
feedback and tests
FBruzzesi f72fcc7
missing condition to xfail
FBruzzesi 5ae3fee
move warnings to pyproject
FBruzzesi 387e089
merge main
FBruzzesi 1bd6ffc
statement order?
FBruzzesi 0fbeb17
pragma no cover branch
FBruzzesi e41cea5
Merge branch 'main' into tests/pyspark-to-main
FBruzzesi e4c8281
Merge branch 'main' into tests/pyspark-to-main
FBruzzesi d56b995
Merge remote-tracking branch 'upstream/main' into test-pyspark
MarcoGorelli 1aba20d
Merge remote-tracking branch 'upstream/main' into test-pyspark
MarcoGorelli 931993e
solve tests conflicts
FBruzzesi 2dd890a
Merge branch 'tests/pyspark-to-main' of https://github.com/narwhals-dβ¦
FBruzzesi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
from typing import TYPE_CHECKING | ||
from typing import Any | ||
from typing import Callable | ||
from typing import Generator | ||
from typing import Sequence | ||
|
||
import pandas as pd | ||
|
@@ -14,7 +13,6 @@ | |
|
||
if TYPE_CHECKING: | ||
import duckdb | ||
from pyspark.sql import SparkSession | ||
|
||
from narwhals.typing import IntoDataFrame | ||
from narwhals.typing import IntoFrame | ||
|
@@ -129,15 +127,15 @@ def pyarrow_table_constructor(obj: Any) -> IntoDataFrame: | |
return pa.table(obj) # type: ignore[no-any-return] | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def spark_session() -> Generator[SparkSession, None, None]: # pragma: no cover | ||
def pyspark_lazy_constructor() -> Callable[[Any], IntoFrame]: # pragma: no cover | ||
try: | ||
from pyspark.sql import SparkSession | ||
except ImportError: # pragma: no cover | ||
pytest.skip("pyspark is not installed") | ||
return | ||
return None | ||
|
||
import warnings | ||
from atexit import register | ||
|
||
os.environ["PYARROW_IGNORE_TIMEZONE"] = "1" | ||
with warnings.catch_warnings(): | ||
|
@@ -155,8 +153,19 @@ def spark_session() -> Generator[SparkSession, None, None]: # pragma: no cover | |
.config("spark.sql.shuffle.partitions", "2") | ||
.getOrCreate() | ||
) | ||
yield session | ||
session.stop() | ||
|
||
register(session.stop) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL |
||
|
||
def _constructor(obj: Any) -> IntoFrame: | ||
pd_df = pd.DataFrame(obj).replace({float("nan"): None}).reset_index() | ||
return ( # type: ignore[no-any-return] | ||
session.createDataFrame(pd_df) | ||
.repartition(2) | ||
.orderBy("index") | ||
.drop("index") | ||
) | ||
|
||
return _constructor | ||
|
||
|
||
EAGER_CONSTRUCTORS: dict[str, Callable[[Any], IntoDataFrame]] = { | ||
|
@@ -173,6 +182,7 @@ def spark_session() -> Generator[SparkSession, None, None]: # pragma: no cover | |
"dask": dask_lazy_p2_constructor, | ||
"polars[lazy]": polars_lazy_constructor, | ||
"duckdb": duckdb_lazy_constructor, | ||
"pyspark": pyspark_lazy_constructor, # type: ignore[dict-item] | ||
} | ||
GPU_CONSTRUCTORS: dict[str, Callable[[Any], IntoFrame]] = {"cudf": cudf_constructor} | ||
|
||
|
@@ -201,7 +211,10 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None: | |
constructors.append(EAGER_CONSTRUCTORS[constructor]) | ||
constructors_ids.append(constructor) | ||
elif constructor in LAZY_CONSTRUCTORS: | ||
constructors.append(LAZY_CONSTRUCTORS[constructor]) | ||
if constructor == "pyspark": | ||
constructors.append(pyspark_lazy_constructor()) | ||
else: | ||
constructors.append(LAZY_CONSTRUCTORS[constructor]) | ||
constructors_ids.append(constructor) | ||
else: # pragma: no cover | ||
msg = f"Expected one of {EAGER_CONSTRUCTORS.keys()} or {LAZY_CONSTRUCTORS.keys()}, got {constructor}" | ||
|
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to implement
Expr.__eq__
to get this to work. It overlaps with @EdAbati PR