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
selector
as 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.
206 207 208 |
# File 'lib/polars/selector.rb', line 206 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).
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/polars/selector.rb', line 138 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 - Selectors.by_name(exclude_cols, require_all: false) 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 |