Class: Arrow::Scalar

Inherits:
Object
  • Object
show all
Defined in:
lib/arrow/scalar.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resolve(scalar) ⇒ Arrow::Scalar .resolve(value) ⇒ Arrow::Scalar .resolve(value, data_type) ⇒ Arrow::Scalar

Ensure returning suitable Arrow::Scalar.

Overloads:

  • .resolve(scalar) ⇒ Arrow::Scalar

    Returns the given scalar itself. This is convenient to use this method as Arrow::Scalar converter.

    Parameters:

    Returns:

  • .resolve(value) ⇒ Arrow::Scalar

    Creates a suitable scalar from the given value. For example, you can create BooleanScalar from ‘true`.

    Parameters:

    • value (Object)

      The value.

    Returns:

  • .resolve(value, data_type) ⇒ Arrow::Scalar

    Creates a scalar of ‘data_type.scalar_class` from the given value. For example, you can create Int32Scalar from `29` and Int32DataType.

    Parameters:

    Returns:

Since:

  • 12.0.0



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/arrow/scalar.rb', line 73

def resolve(value, data_type=nil)
  return try_convert(value) if data_type.nil?

  data_type = DataType.resolve(data_type)
  scalar_class = data_type.scalar_class
  case value
  when Scalar
    return value if value.class == scalar_class
    value = value.value
  end
  scalar_class.new(value)
end

.try_convert(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/arrow/scalar.rb', line 22

def try_convert(value)
  case value
  when self
    value
  when true, false
    BooleanScalar.new(value)
  when Symbol, String
    StringScalar.new(value.to_s)
  when Integer
    Int64Scalar.new(value)
  when Float
    DoubleScalar.new(value)
  else
    nil
  end
end

Instance Method Details

#equal_scalar?(other, options = nil) ⇒ Boolean

Returns ‘true` if both of them have the same data, `false` otherwise.

Parameters:

Returns:

  • (Boolean)

    ‘true` if both of them have the same data, `false` otherwise.

Since:

  • 5.0.0



95
96
97
# File 'lib/arrow/scalar.rb', line 95

def equal_scalar?(other, options=nil)
  equal_options(other, options)
end