Class: Polars::DataTypeExpr

Inherits:
Object
  • Object
show all
Defined in:
lib/polars/data_type_expr.rb

Overview

A lazily instantiated DataType that can be used in an Expr.

Instance Method Summary collapse

Instance Method Details

#collect_dtype(context) ⇒ DataType

Materialize the DataTypeExpr in a specific context.

This is a useful function when debugging datatype expressions.

Examples:

lf = Polars::LazyFrame.new(
  {
    "a" => [1, 2, 3]
  }
)
Polars.dtype_of("a").collect_dtype(lf)
# => Polars::Int64
Polars.dtype_of("a").collect_dtype({"a" => Polars::String})
# => Polars::String

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/polars/data_type_expr.rb', line 32

def collect_dtype(
  context
)
  schema = nil
  if context.is_a?(Schema)
     schema = context
  elsif context.is_a?(Hash)
    schema = Schema.new(context)
  elsif context.is_a?(DataFrame)
    schema = context.schema
  elsif context.is_a?(LazyFrame)
    schema = context.collect_schema
  else
    msg = "DataTypeExpr.collect_dtype did not expect #{context.inspect}"
    raise TypeError, msg
  end

  _rbdatatype_expr.collect_dtype(schema.to_h)
end