@@ -77,6 +77,22 @@ def test_new_struct_symbol_keys
7777 assert_series [ 1 , nil , 3 ] , s . struct [ "f1" ] , dtype : Polars ::Int64
7878 end
7979
80+ def test_new_struct_different_keys
81+ s = Polars ::Series . new ( [ { "f1" => 1 } , nil , { "f2" => 3.5 } ] )
82+ # same behavior as Python
83+ assert_series [ { "f1" => 1 } , nil , { "f1" => nil } ] , s , dtype : Polars ::Struct
84+ assert_equal ( { "f1" => Polars ::Int64 } , s . dtype . to_schema )
85+ assert_series [ 1 , nil , nil ] , s . struct [ "f1" ] , dtype : Polars ::Int64
86+ end
87+
88+ def test_new_struct_different_keys_dtype
89+ s = Polars ::Series . new ( [ { "f1" => 1 } , nil , { "f2" => 3.5 } ] , dtype : Polars ::Struct )
90+ assert_series [ { "f1" => 1 , "f2" => nil } , nil , { "f1" => nil , "f2" => 3.5 } ] , s , dtype : Polars ::Struct
91+ assert_equal ( { "f1" => Polars ::Int64 , "f2" => Polars ::Float64 } , s . dtype . to_schema )
92+ assert_series [ 1 , nil , nil ] , s . struct [ "f1" ] , dtype : Polars ::Int64
93+ assert_series [ nil , nil , 3.5 ] , s . struct [ "f2" ] , dtype : Polars ::Float64
94+ end
95+
8096 def test_new_struct_nested
8197 data = [
8298 { "a" => { "b" => { "c" => 1 } } } ,
0 commit comments