Skip to content

Commit 4e43f54

Browse files
authored
ci: unxfail truncate tests for pyspark by checking local results (#2794)
1 parent f2c8dd7 commit 4e43f54

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

tests/expr_and_series/dt/truncate_test.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ def test_truncate(
5353
every: str,
5454
expected: list[datetime],
5555
) -> None:
56-
if any(x in str(constructor) for x in ("sqlframe", "pyspark")):
57-
# TODO(marco): investigate pyspark, it also localizes to UTC here.
58-
request.applymarker(
59-
pytest.mark.xfail(reason="https://github.com/eakmanrq/sqlframe/issues/383")
60-
)
6156
if every.endswith("ns") and any(
6257
x in str(constructor) for x in ("polars", "duckdb", "pyspark", "ibis")
6358
):
@@ -109,11 +104,10 @@ def test_truncate_multiples(
109104
every: str,
110105
expected: list[datetime],
111106
) -> None:
112-
if any(x in str(constructor) for x in ("sqlframe", "cudf", "pyspark", "duckdb")):
107+
if any(x in str(constructor) for x in ("cudf", "pyspark", "duckdb")):
113108
# Reasons:
114-
# - sqlframe: https://github.com/eakmanrq/sqlframe/issues/383
115109
# - cudf: https://github.com/rapidsai/cudf/issues/18654
116-
# - pyspark: Only multiple 1 is currently supported
110+
# - pyspark/sqlframe: Only multiple 1 is currently supported
117111
request.applymarker(pytest.mark.xfail())
118112
if every.endswith("ns") and any(
119113
x in str(constructor) for x in ("polars", "duckdb", "ibis")

tests/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def assert_equal_data(result: Any, expected: Mapping[str, Any]) -> None:
7777
hasattr(result, "_compliant_frame")
7878
and result._compliant_frame._implementation is Implementation.IBIS
7979
)
80+
is_spark_like = (
81+
hasattr(result, "_compliant_frame")
82+
and result._compliant_frame._implementation.is_spark_like()
83+
)
8084
if is_duckdb:
8185
result = from_native(result.to_native().arrow())
8286
if is_ibis:
@@ -122,6 +126,17 @@ def assert_equal_data(result: Any, expected: Mapping[str, Any]) -> None:
122126
are_equivalent_values = pd.isna(rhs)
123127
elif type(lhs) is date and type(rhs) is datetime:
124128
are_equivalent_values = datetime(lhs.year, lhs.month, lhs.day) == rhs
129+
elif (
130+
is_spark_like
131+
and isinstance(lhs, datetime)
132+
and isinstance(rhs, datetime)
133+
and rhs.tzinfo is None
134+
and lhs.tzinfo
135+
):
136+
# PySpark converts timezone-naive to timezone-aware by default in many cases.
137+
# For now, we just assert that the local result matches the expected one.
138+
# https://github.com/narwhals-dev/narwhals/issues/2793
139+
are_equivalent_values = lhs.replace(tzinfo=None) == rhs
125140
else:
126141
are_equivalent_values = lhs == rhs
127142

0 commit comments

Comments
 (0)