Class: Polars::Schema
- Inherits:
-
Object
- Object
- Polars::Schema
- Includes:
- Enumerable
- 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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/polars/schema.rb', line 10 def initialize(schema = nil, check_dtypes: true) @schema = {} if schema.respond_to?(:arrow_c_schema) && !schema.is_a?(Schema) Plr.init_polars_schema_from_arrow_c_schema(@schema, schema) return end input = 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.
33 34 35 |
# File 'lib/polars/schema.rb', line 33 def [](key) @schema[key] end |
#[]=(name, dtype) ⇒ Object
Sets the data type of the column.
40 41 42 43 |
# File 'lib/polars/schema.rb', line 40 def []=(name, dtype) _check_dtype(dtype) @schema[name] = dtype end |
#dtypes ⇒ Array
Get the data types of the schema.
70 71 72 |
# File 'lib/polars/schema.rb', line 70 def dtypes @schema.values end |
#length ⇒ Integer
Get the number of schema entries.
82 83 84 |
# File 'lib/polars/schema.rb', line 82 def length @schema.length end |
#names ⇒ Array
Get the column names of the schema.
58 59 60 |
# File 'lib/polars/schema.rb', line 58 def names @schema.keys end |
#to_s ⇒ String Also known as: inspect
Returns a string representing the Schema.
89 90 91 |
# File 'lib/polars/schema.rb', line 89 def to_s "#{self.class.name}(#{@schema})" end |