Skip to content

Commit 039b417

Browse files
authored
fix: Differentiate between empty list an no list for unpivot (#129)
1 parent 8e85d5a commit 039b417

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

lib/polars/data_frame.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4593,7 +4593,8 @@ def pivot(
45934593
#
45944594
# @param on [Object]
45954595
# Column(s) or selector(s) to use as values variables; if `on`
4596-
# is empty all columns that are not in `index` will be used.
4596+
# is empty no columns will be used. If set to `nil` (default)
4597+
# all columns that are not in `index` will be used.
45974598
# @param index [Object]
45984599
# Column(s) or selector(s) to use as identifier variables.
45994600
# @param variable_name [Object]
@@ -4627,7 +4628,7 @@ def pivot(
46274628
# # │ z ┆ c ┆ 6 │
46284629
# # └─────┴──────────┴───────┘
46294630
def unpivot(on = nil, index: nil, variable_name: nil, value_name: nil)
4630-
on = on.nil? ? [] : Utils._expand_selectors(self, on)
4631+
on = on.nil? ? nil : Utils._expand_selectors(self, on)
46314632
index = index.nil? ? [] : Utils._expand_selectors(self, index)
46324633

46334634
_from_rbdf(_df.unpivot(on, index, value_name, variable_name))

lib/polars/lazy_frame.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,7 +4772,8 @@ def pivot(
47724772
#
47734773
# @param on [Object]
47744774
# Column(s) or selector(s) to use as values variables; if `on`
4775-
# is empty all columns that are not in `index` will be used.
4775+
# is empty no columns will be used. If set to `nil` (default)
4776+
# all columns that are not in `index` will be used.
47764777
# @param index [Object]
47774778
# Column(s) or selector(s) to use as identifier variables.
47784779
# @param variable_name [String]
@@ -4820,12 +4821,12 @@ def unpivot(
48204821
warn "The `streamable` parameter for `LazyFrame.unpivot` is deprecated"
48214822
end
48224823

4823-
selector_on = on.nil? ? Selectors.empty : Utils.parse_list_into_selector(on)
4824+
selector_on = on.nil? ? nil : Utils.parse_list_into_selector(on)._rbselector
48244825
selector_index = index.nil? ? Selectors.empty : Utils.parse_list_into_selector(index)
48254826

48264827
_from_rbldf(
48274828
_ldf.unpivot(
4828-
selector_on._rbselector,
4829+
selector_on,
48294830
selector_index._rbselector,
48304831
value_name,
48314832
variable_name

0 commit comments

Comments
 (0)