Class: Polars::Schema
- Inherits:
-
Object
- Object
- Polars::Schema
- Defined in:
- lib/polars/schema.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the data type of the column.
-
#[]=(name, dtype) ⇒ Object
Sets the data type of the column.
-
#dtypes ⇒ Array
Get the data types of the schema.
-
#initialize(schema = nil, check_dtypes: true) ⇒ Schema
constructor
Ordered mapping of column names to their data type.
-
#length ⇒ Integer
Get the number of schema entries.
-
#names ⇒ Array
Get the column names of the schema.
-
#to_s ⇒ String
(also: #inspect)
Returns a string representing the Schema.
Constructor Details
#initialize(schema = nil, check_dtypes: true) ⇒ Schema
Ordered mapping of column names to their data type.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/polars/schema.rb', line 8 def initialize(schema = nil, check_dtypes: true) input = schema || {} @schema = {} input.each do |name, tp| if !check_dtypes @schema[name] = tp elsif Utils.is_polars_dtype(tp) @schema[name] = _check_dtype(tp) else self[name] = tp end end end |
Instance Method Details
#[](key) ⇒ Object
Returns the data type of the column.
25 26 27 |
# File 'lib/polars/schema.rb', line 25 def [](key) @schema[key] end |
#[]=(name, dtype) ⇒ Object
Sets the data type of the column.
32 33 34 35 |
# File 'lib/polars/schema.rb', line 32 def []=(name, dtype) _check_dtype(dtype) @schema[name] = dtype end |
#dtypes ⇒ Array
Get the data types of the schema.
57 58 59 |
# File 'lib/polars/schema.rb', line 57 def dtypes @schema.values end |
#length ⇒ Integer
Get the number of schema entries.
69 70 71 |
# File 'lib/polars/schema.rb', line 69 def length @schema.length end |
#names ⇒ Array
Get the column names of the schema.
45 46 47 |
# File 'lib/polars/schema.rb', line 45 def names @schema.keys end |
#to_s ⇒ String Also known as: inspect
Returns a string representing the Schema.
76 77 78 |
# File 'lib/polars/schema.rb', line 76 def to_s "#{self.class.name}(#{@schema})" end |