@@ -522,27 +522,32 @@ def self.from_config(config, dataset, action: :create)
522522 EasyML ::Import ::Column . from_config ( config , dataset , action : action )
523523 end
524524
525- def cast_statement ( df , df_col , expected_dtype )
526- expected_dtype = expected_dtype . is_a? ( Polars ::DataType ) ? expected_dtype . class : expected_dtype
527- actual_type = df [ df_col ] . dtype
525+ def cast_statement ( series = nil )
526+ expected_dtype = polars_datatype
527+ actual_type = series &.dtype || expected_dtype
528+
529+ return Polars . col ( name ) . cast ( expected_dtype ) . alias ( name ) if expected_dtype == actual_type
528530
529531 cast_statement = case expected_dtype . to_s
530- when "Polars::Boolean"
532+ when /Polars::List/
533+ # we should start tracking polars args so we can know what type of list it is
534+ Polars . col ( name )
535+ when /Polars::Boolean/
531536 case actual_type . to_s
532- when " Polars::Boolean"
533- Polars . col ( df_col ) . cast ( expected_dtype )
534- when " Polars::Utf8" , " Polars::Categorical" , " Polars::String"
535- Polars . col ( df_col ) . eq ( "true" ) . cast ( expected_dtype )
536- when " Polars::Null"
537- Polars . col ( df_col )
537+ when / Polars::Boolean/ , /Polars::Int/
538+ Polars . col ( name ) . cast ( expected_dtype )
539+ when / Polars::Utf/ , / Polars::Categorical/ , / Polars::String/
540+ Polars . col ( name ) . eq ( "true" ) . cast ( expected_dtype )
541+ when / Polars::Null/
542+ Polars . col ( name )
538543 else
539- raise "Unexpected dtype: #{ actual_type } for column: #{ df_col } "
544+ raise "Unexpected dtype: #{ actual_type } for column: #{ name } "
540545 end
541546 else
542- Polars . col ( df_col ) . cast ( expected_dtype )
547+ Polars . col ( name ) . cast ( expected_dtype , strict : false )
543548 end
544549
545- cast_statement . alias ( df_col )
550+ cast_statement . alias ( name )
546551 end
547552
548553 def cast ( value )
0 commit comments