Skip to content

Commit d2a9f42

Browse files
fix: unpivot was unnecessary failing for PySpark/SQLFrame when neither on nor index were passed (#2335)
* fix: unpivot was unnecessary failing for PySpark/SQLFrame when neither `on` nor `index` were passed * Update narwhals/_spark_like/dataframe.py Co-authored-by: Dan Redding <[email protected]> --------- Co-authored-by: Dan Redding <[email protected]>
1 parent 41d5a5c commit d2a9f42

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

narwhals/_spark_like/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def unpivot(
495495
else: # pragma: no cover
496496
pass
497497

498-
ids = tuple(self.columns) if index is None else tuple(index)
498+
ids = tuple(index) if index else ()
499499
values = (
500500
tuple(set(self.columns).difference(set(ids))) if on is None else tuple(on)
501501
)

tests/frame/unpivot_test.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
from narwhals.stable.v1.dtypes import DType
1616

1717
data = {
18-
"a": ["x", "y", "z"],
18+
"a": [7, 8, 9],
1919
"b": [1, 3, 5],
2020
"c": [2, 4, 6],
2121
}
2222

2323
expected_on_b_idx_a = {
24-
"a": ["x", "y", "z"],
24+
"a": [7, 8, 9],
2525
"variable": ["b", "b", "b"],
2626
"value": [1, 3, 5],
2727
}
2828

2929
expected_on_b_c_idx_a = {
30-
"a": ["x", "y", "z", "x", "y", "z"],
30+
"a": [7, 8, 9, 7, 8, 9],
3131
"variable": ["b", "b", "b", "c", "c", "c"],
3232
"value": [1, 3, 5, 2, 4, 6],
3333
}
3434

3535
expected_on_none_idx_a = {
36-
"a": ["x", "y", "z", "x", "y", "z"],
36+
"a": [7, 8, 9, 7, 8, 9],
3737
"variable": ["b", "b", "b", "c", "c", "c"],
3838
"value": [1, 3, 5, 2, 4, 6],
3939
}
@@ -45,7 +45,7 @@
4545

4646
expected_on_none_idx_none = {
4747
"variable": ["a", "a", "a", "b", "b", "b", "c", "c", "c"],
48-
"value": ["x", "y", "z", "1", "3", "5", "2", "4", "6"],
48+
"value": [7, 8, 9, 1, 3, 5, 2, 4, 6],
4949
}
5050

5151

@@ -64,11 +64,7 @@ def test_unpivot(
6464
on: str | list[str] | None,
6565
index: list[str] | None,
6666
expected: dict[str, list[float]],
67-
request: pytest.FixtureRequest,
6867
) -> None:
69-
if on is None and index is None and "polars" not in str(constructor):
70-
# TODO(2082): add support in other backends
71-
request.applymarker(pytest.mark.xfail)
7268
df = nw.from_native(constructor(data))
7369
sort_columns = ["variable"] if index is None else ["variable", "a"]
7470
result = df.unpivot(on=on, index=index).sort(by=sort_columns)

0 commit comments

Comments
 (0)