Skip to content

Filesystem: Properly forward omniload reader hints to Polars read_xyz kwargs #214

Description

@amotl

Problem

In omniload.source.filesystem.adapter:resource_for_reader, we are currently using a very basic implementation to forward omniload reader hints to Polars read_xyz kwargs, which does not support casting ingress parameters (all str) to their designated target types as defined by Polars' function signature. In this spirit, the procedure currently just barely works for string argument types.

reader = reader.bind(**ref.hints)

Because no type conversion takes place, it is currently not possible to convey int, float, bool, nor any container types like list or dict.

Solution

Short-term, in order to forward all kwargs to polars.read_excel properly, let's either supply a custom mapper tailored to the problem at hand, or, more generic, introspect the target read_excel function to learn about relevant types at runtime to be able to automatically cast them to their expected types, when possible. For list and dict types, let's use compact JSON as serialized representation (no whitespace), when possible.

Outlook

In the long run, this could be another candidate for a more thorough approach using Pydantic.

Originally posted by @amotl in #123 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions