Skip to content

Commit

Permalink
Fixed Array test
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 7, 2023
1 parent ba9b180 commit 72d51a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/polars/data_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ def to_s
class Array < NestedType
attr_reader :width, :inner

def initialize(width, inner)
def initialize(width, inner = nil)
@width = width
@inner = Utils.rb_type_to_dtype(inner)
@inner = Utils.rb_type_to_dtype(inner) if inner
end

# TODO check width?
Expand Down
6 changes: 5 additions & 1 deletion lib/polars/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3846,6 +3846,10 @@ def sequence_to_rbseries(name, values, dtype: nil, strict: true, dtype_if_empty:
end

if !dtype.nil? && ![List, Unknown].include?(dtype) && Utils.is_polars_dtype(dtype) && ruby_dtype.nil?
if dtype == Array && !dtype.is_a?(Array) && value.is_a?(::Array)
dtype = Array.new(value.size)
end

constructor = polars_type_to_constructor(dtype)
rbseries = constructor.call(name, values, strict)

Expand Down Expand Up @@ -3966,7 +3970,7 @@ def sequence_from_anyvalue_or_object(name, values)
}

def polars_type_to_constructor(dtype)
if dtype == Array || dtype.is_a?(Array)
if dtype.is_a?(Array)
lambda do |name, values, strict|
RbSeries.new_array(dtype.width, dtype.inner, name, values, strict)
end
Expand Down
2 changes: 0 additions & 2 deletions test/types_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ def test_series_dtype_list_dtype
end

def test_series_dtype_array
skip # TODO fix

s = Polars::Series.new([[1, 2], [3, 4]], dtype: Polars::Array)
assert_series [[1, 2], [3, 4]], s, dtype: Polars::Array.new(2, Polars::Int64)
end
Expand Down

0 comments on commit 72d51a5

Please sign in to comment.