Module: Polars::Selectors
- Defined in:
- lib/polars/selectors.rb
Class Method Summary collapse
-
.all ⇒ SelectorProxy
Select all columns.
-
.alpha(ascii_only: false, ignore_spaces: false) ⇒ SelectorProxy
Select all columns with alphabetic names (eg: only letters).
-
.binary ⇒ SelectorProxy
Select all binary columns.
-
.boolean ⇒ SelectorProxy
Select all boolean columns.
-
.categorical ⇒ SelectorProxy
Select all categorical columns.
-
.contains(*substring) ⇒ SelectorProxy
Select columns whose names contain the given literal substring(s).
-
.date ⇒ SelectorProxy
Select all date columns.
-
.decimal ⇒ SelectorProxy
Select all decimal columns.
-
.ends_with(*suffix) ⇒ SelectorProxy
Select columns that end with the given substring(s).
-
.first ⇒ SelectorProxy
Select the first column in the current scope.
-
.float ⇒ SelectorProxy
Select all float columns.
-
.integer ⇒ SelectorProxy
Select all integer columns.
-
.last ⇒ SelectorProxy
Select the last column in the current scope.
-
.numeric ⇒ SelectorProxy
Select all numeric columns.
-
.signed_integer ⇒ SelectorProxy
Select all signed integer columns.
-
.starts_with(*prefix) ⇒ SelectorProxy
Select columns that start with the given substring(s).
-
.string(include_categorical: false) ⇒ SelectorProxy
Select all String (and, optionally, Categorical) string columns.
-
.time ⇒ SelectorProxy
Select all time columns.
-
.unsigned_integer ⇒ SelectorProxy
Select all unsigned integer columns.
Class Method Details
.all ⇒ SelectorProxy
Select all columns.
172 173 174 |
# File 'lib/polars/selectors.rb', line 172 def self.all _selector_proxy_(F.all, name: "all") end |
.alpha(ascii_only: false, ignore_spaces: false) ⇒ SelectorProxy
Matching column names cannot contain any non-alphabetic characters. Note
that the definition of "alphabetic" consists of all valid Unicode alphabetic
characters (\p{Alphabetic}
) by default; this can be changed by setting
ascii_only: true
.
Select all columns with alphabetic names (eg: only letters).
273 274 275 276 277 278 279 280 281 282 |
# File 'lib/polars/selectors.rb', line 273 def self.alpha(ascii_only: false, ignore_spaces: false) # note that we need to supply a pattern compatible with the *rust* regex crate re_alpha = ascii_only ? "a-zA-Z" : "\\p{Alphabetic}" re_space = ignore_spaces ? " " : "" _selector_proxy_( F.col("^[#{re_alpha}#{re_space}]+$"), name: "alpha", parameters: {"ascii_only" => ascii_only, "ignore_spaces" => ignore_spaces}, ) end |
.binary ⇒ SelectorProxy
Select all binary columns.
311 312 313 |
# File 'lib/polars/selectors.rb', line 311 def self.binary _selector_proxy_(F.col(Binary), name: "binary") end |
.boolean ⇒ SelectorProxy
Select all boolean columns.
363 364 365 |
# File 'lib/polars/selectors.rb', line 363 def self.boolean _selector_proxy_(F.col(Boolean), name: "boolean") end |
.categorical ⇒ SelectorProxy
Select all categorical columns.
418 419 420 |
# File 'lib/polars/selectors.rb', line 418 def self.categorical _selector_proxy_(F.col(Categorical), name: "categorical") end |
.contains(*substring) ⇒ SelectorProxy
Select columns whose names contain the given literal substring(s).
477 478 479 480 481 482 483 484 485 486 |
# File 'lib/polars/selectors.rb', line 477 def self.contains(*substring) escaped_substring = _re_string(substring) raw_params = "^.*#{escaped_substring}.*$" _selector_proxy_( F.col(raw_params), name: "contains", parameters: {"*substring" => escaped_substring} ) end |
.date ⇒ SelectorProxy
Select all date columns.
525 526 527 |
# File 'lib/polars/selectors.rb', line 525 def self.date _selector_proxy_(F.col(Date), name: "date") end |
.decimal ⇒ SelectorProxy
Select all decimal columns.
573 574 575 576 |
# File 'lib/polars/selectors.rb', line 573 def self.decimal # TODO: allow explicit selection by scale/precision? _selector_proxy_(F.col(Decimal), name: "decimal") end |
.ends_with(*suffix) ⇒ SelectorProxy
Select columns that end with the given substring(s).
633 634 635 636 637 638 639 640 641 642 |
# File 'lib/polars/selectors.rb', line 633 def self.ends_with(*suffix) escaped_suffix = _re_string(suffix) raw_params = "^.*#{escaped_suffix}$" _selector_proxy_( F.col(raw_params), name: "ends_with", parameters: {"*suffix" => escaped_suffix}, ) end |
.first ⇒ SelectorProxy
Select the first column in the current scope.
683 684 685 |
# File 'lib/polars/selectors.rb', line 683 def self.first _selector_proxy_(F.first, name: "first") end |
.float ⇒ SelectorProxy
Select all float columns.
727 728 729 |
# File 'lib/polars/selectors.rb', line 727 def self.float _selector_proxy_(F.col(FLOAT_DTYPES), name: "float") end |
.integer ⇒ SelectorProxy
Select all integer columns.
770 771 772 |
# File 'lib/polars/selectors.rb', line 770 def self.integer _selector_proxy_(F.col(INTEGER_DTYPES), name: "integer") end |
.last ⇒ SelectorProxy
Select the last column in the current scope.
927 928 929 |
# File 'lib/polars/selectors.rb', line 927 def self.last _selector_proxy_(F.last, name: "last") end |
.numeric ⇒ SelectorProxy
Select all numeric columns.
971 972 973 |
# File 'lib/polars/selectors.rb', line 971 def self.numeric _selector_proxy_(F.col(NUMERIC_DTYPES), name: "numeric") end |
.signed_integer ⇒ SelectorProxy
Select all signed integer columns.
827 828 829 |
# File 'lib/polars/selectors.rb', line 827 def self.signed_integer _selector_proxy_(F.col(SIGNED_INTEGER_DTYPES), name: "signed_integer") end |
.starts_with(*prefix) ⇒ SelectorProxy
Select columns that start with the given substring(s).
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 |
# File 'lib/polars/selectors.rb', line 1030 def self.starts_with(*prefix) escaped_prefix = _re_string(prefix) raw_params = "^#{escaped_prefix}.*$" _selector_proxy_( F.col(raw_params), name: "starts_with", parameters: {"*prefix" => prefix} ) end |
.string(include_categorical: false) ⇒ SelectorProxy
Select all String (and, optionally, Categorical) string columns.
df.group_by(Polars.cs.string).agg(Polars.cs.numeric.sum).sort(Polars.cs.string) shape: (2, 3) ┌─────┬─────┬─────┐ │ w ┆ x ┆ y │ │ --- ┆ --- ┆ --- │ │ str ┆ i64 ┆ f64 │ ╞═════╪═════╪═════╡ │ xx ┆ 0 ┆ 2.0 │ │ yy ┆ 6 ┆ 7.0 │ └─────┴─────┴─────┘
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 |
# File 'lib/polars/selectors.rb', line 1084 def self.string(include_categorical: false) string_dtypes = [String] if include_categorical string_dtypes << Categorical end _selector_proxy_( F.col(string_dtypes), name: "string", parameters: {"include_categorical" => include_categorical}, ) end |
.time ⇒ SelectorProxy
Select all time columns.
1136 1137 1138 |
# File 'lib/polars/selectors.rb', line 1136 def self.time _selector_proxy_(F.col(Time), name: "time") end |
.unsigned_integer ⇒ SelectorProxy
Select all unsigned integer columns.
884 885 886 |
# File 'lib/polars/selectors.rb', line 884 def self.unsigned_integer _selector_proxy_(F.col(UNSIGNED_INTEGER_DTYPES), name: "unsigned_integer") end |