Class: Polars::Selector
Overview
Base column selector expression/proxy.
Instance Method Summary collapse
-
#&(other) ⇒ Selector
AND.
-
#-(other) ⇒ Selector
Difference.
-
#^(other) ⇒ Selector
XOR.
-
#as_expr ⇒ Expr
Materialize the
selectoras a normal expression. -
#exclude(columns, *more_columns) ⇒ Selector
Exclude columns from a multi-column expression.
-
#inspect ⇒ String
Returns a string representing the Selector.
-
#|(other) ⇒ Selector
OR.
-
#~ ⇒ Selector
Invert the selector.
Instance Method Details
#&(other) ⇒ Selector
AND.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/polars/selector.rb', line 66 def &(other) if Utils.is_column(other) colname = other..output_name other = by_name(colname) end if Utils.is_selector(other) Selector._from_rbselector( _rbselector.intersect(other._rbselector) ) else as_expr & other end end |
#-(other) ⇒ Selector
Difference.
99 100 101 102 103 104 105 106 107 |
# File 'lib/polars/selector.rb', line 99 def -(other) if Utils.is_selector(other) Selector._from_rbselector( _rbselector.difference(other._rbselector) ) else as_expr - other end end |
#^(other) ⇒ Selector
XOR.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/polars/selector.rb', line 112 def ^(other) if Utils.is_column(other) other = by_name(other..output_name) end if Utils.is_selector(other) Selector._from_rbselector( _rbselector.exclusive_or(other._rbselector) ) else as_expr ^ other end end |
#as_expr ⇒ Expr
Materialize the selector as a normal expression.
This ensures that the operators |, &, ~ and -
are applied on the data and not on the selector sets.
241 242 243 |
# File 'lib/polars/selector.rb', line 241 def as_expr Expr._from_rbexpr(_rbexpr) end |
#exclude(columns, *more_columns) ⇒ Selector
Exclude columns from a multi-column expression.
Only works after a wildcard or regex column selection, and you cannot provide both string column names and dtypes (you may prefer to use selectors instead).
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/polars/selector.rb', line 173 def exclude(columns, *more_columns) exclude_cols = [] exclude_dtypes = [] ((columns.is_a?(::Array) ? columns : [columns]) + more_columns).each do |item| if item.is_a?(::String) exclude_cols << item elsif Utils.is_polars_dtype(item) exclude_dtypes << item else msg = ( "invalid input for `exclude`" + "\n\nExpected one or more `str` or `DataType`; found #{item.inspect} instead." ) raise TypeError, msg end end if exclude_cols.any? && exclude_dtypes.any? msg = "cannot exclude by both column name and dtype; use a selector instead" raise TypeError, msg elsif exclude_dtypes.any? self - Selectors.by_dtype(exclude_dtypes) else self - Selector._by_name(exclude_cols, strict: false, expand_patterns: true) end end |
#inspect ⇒ String
Returns a string representing the Selector.
18 19 20 |
# File 'lib/polars/selector.rb', line 18 def inspect Expr._from_rbexpr(_rbexpr).to_s end |
#|(other) ⇒ Selector
OR.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/polars/selector.rb', line 83 def |(other) if Utils.is_column(other) other = by_name(other..output_name) end if Utils.is_selector(other) Selector._from_rbselector( _rbselector.union(other._rbselector) ) else as_expr | other end end |
#~ ⇒ Selector
Invert the selector.
59 60 61 |
# File 'lib/polars/selector.rb', line 59 def ~ Selectors.all - self end |