Class: Polars::ScanCastOptions

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

Overview

Options for scanning files.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(integer_cast: "forbid", float_cast: "forbid", datetime_cast: "forbid", missing_struct_fields: "raise", extra_struct_fields: "raise", _internal_call: false) ⇒ ScanCastOptions

Note:

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

Common configuration for scanning files.

Parameters:

  • integer_cast ('upcast', 'forbid') (defaults to: "forbid")

    Configuration for casting from integer types:

    • upcast: Allow lossless casting to wider integer types.
    • forbid: Raises an error if dtypes do not match.
  • float_cast ('upcast', 'downcast', 'forbid') (defaults to: "forbid")

    Configuration for casting from float types:

    • upcast: Allow casting to higher precision float types.
    • downcast: Allow casting to lower precision float types.
    • forbid: Raises an error if dtypes do not match.
  • datetime_cast ('nanosecond-downcast', 'convert-timezone', 'forbid') (defaults to: "forbid")

    Configuration for casting from datetime types:

    • nanosecond-downcast: Allow nanosecond precision datetime to be downcasted to any lower precision. This has a similar effect to PyArrow's coerce_int96_timestamp_unit.
    • convert-timezone: Allow casting to a different timezone.
    • forbid: Raises an error if dtypes do not match.
  • missing_struct_fields ('insert', 'raise') (defaults to: "raise")

    Configuration for behavior when struct fields defined in the schema are missing from the data:

    • insert: Inserts the missing fields.
    • raise: Raises an error.
  • extra_struct_fields ('ignore', 'raise') (defaults to: "raise")

    Configuration for behavior when extra struct fields outside of the defined schema are encountered in the data:

    • ignore: Silently ignores.
    • raise: Raises an error.


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/polars/scan_cast_options.rb', line 47

def initialize(
  integer_cast: "forbid",
  float_cast: "forbid",
  datetime_cast: "forbid",
  missing_struct_fields: "raise",
  extra_struct_fields: "raise",
  _internal_call: false
)
  if !_internal_call
    warn "ScanCastOptions is considered unstable."
  end

  @integer_cast = integer_cast
  @float_cast = float_cast
  @datetime_cast = datetime_cast
  @missing_struct_fields = missing_struct_fields
  @extra_struct_fields = extra_struct_fields
end

Instance Attribute Details

#datetime_castObject (readonly)

Returns the value of attribute datetime_cast.



4
5
6
# File 'lib/polars/scan_cast_options.rb', line 4

def datetime_cast
  @datetime_cast
end

#extra_struct_fieldsObject (readonly)

Returns the value of attribute extra_struct_fields.



4
5
6
# File 'lib/polars/scan_cast_options.rb', line 4

def extra_struct_fields
  @extra_struct_fields
end

#float_castObject (readonly)

Returns the value of attribute float_cast.



4
5
6
# File 'lib/polars/scan_cast_options.rb', line 4

def float_cast
  @float_cast
end

#integer_castObject (readonly)

Returns the value of attribute integer_cast.



4
5
6
# File 'lib/polars/scan_cast_options.rb', line 4

def integer_cast
  @integer_cast
end

#missing_struct_fieldsObject (readonly)

Returns the value of attribute missing_struct_fields.



4
5
6
# File 'lib/polars/scan_cast_options.rb', line 4

def missing_struct_fields
  @missing_struct_fields
end

Class Method Details

._defaultObject



66
67
68
# File 'lib/polars/scan_cast_options.rb', line 66

def self._default
  new(_internal_call: true)
end

._default_icebergObject



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/polars/scan_cast_options.rb', line 70

def self._default_iceberg
  @_default_cast_options_iceberg ||= begin
    ScanCastOptions.new(
      integer_cast: "upcast",
      float_cast: ["upcast", "downcast"],
      datetime_cast: ["nanosecond-downcast", "convert-timezone"],
      missing_struct_fields: "insert",
      extra_struct_fields: "ignore",
      _internal_call: true
    )
  end
end