|
| 1 | +module Polars |
| 2 | + # Options for scanning files. |
| 3 | + class ScanCastOptions |
| 4 | + # Common configuration for scanning files. |
| 5 | + # |
| 6 | + # @note |
| 7 | + # This functionality is considered **unstable**. It may be changed |
| 8 | + # at any point without it being considered a breaking change. |
| 9 | + # |
| 10 | + # @param integer_cast ['upcast', 'forbid'] |
| 11 | + # Configuration for casting from integer types: |
| 12 | + # |
| 13 | + # * `upcast`: Allow lossless casting to wider integer types. |
| 14 | + # * `forbid`: Raises an error if dtypes do not match. |
| 15 | + # |
| 16 | + # @param float_cast ['upcast', 'downcast', 'forbid'] |
| 17 | + # Configuration for casting from float types: |
| 18 | + # |
| 19 | + # * `upcast`: Allow casting to higher precision float types. |
| 20 | + # * `downcast`: Allow casting to lower precision float types. |
| 21 | + # * `forbid`: Raises an error if dtypes do not match. |
| 22 | + # |
| 23 | + # @param datetime_cast ['nanosecond-downcast', 'convert-timezone', 'forbid'] |
| 24 | + # Configuration for casting from datetime types: |
| 25 | + # |
| 26 | + # * `nanosecond-downcast`: Allow nanosecond precision datetime to be |
| 27 | + # downcasted to any lower precision. This has a similar effect to |
| 28 | + # PyArrow's `coerce_int96_timestamp_unit`. |
| 29 | + # * `convert-timezone`: Allow casting to a different timezone. |
| 30 | + # * `forbid`: Raises an error if dtypes do not match. |
| 31 | + # |
| 32 | + # @param missing_struct_fields ['insert', 'raise'] |
| 33 | + # Configuration for behavior when struct fields defined in the schema |
| 34 | + # are missing from the data: |
| 35 | + # |
| 36 | + # * `insert`: Inserts the missing fields. |
| 37 | + # * `raise`: Raises an error. |
| 38 | + # |
| 39 | + # @param extra_struct_fields ['ignore', 'raise'] |
| 40 | + # Configuration for behavior when extra struct fields outside of the |
| 41 | + # defined schema are encountered in the data: |
| 42 | + # |
| 43 | + # * `ignore`: Silently ignores. |
| 44 | + # * `raise`: Raises an error. |
| 45 | + def initialize( |
| 46 | + integer_cast: "forbid", |
| 47 | + float_cast: "forbid", |
| 48 | + datetime_cast: "forbid", |
| 49 | + missing_struct_fields: "raise", |
| 50 | + extra_struct_fields: "raise", |
| 51 | + _internal_call: false |
| 52 | + ) |
| 53 | + @integer_cast = integer_cast |
| 54 | + @float_cast = float_cast |
| 55 | + @datetime_cast = datetime_cast |
| 56 | + @missing_struct_fields = missing_struct_fields |
| 57 | + @extra_struct_fields = extra_struct_fields |
| 58 | + end |
| 59 | + |
| 60 | + def self.default |
| 61 | + new(_internal_call: true) |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments