[Python] Is it possible in polars to give the full schema of a LazyFrame/DataFrame in a...

Discussão em 'Python' iniciado por Stack, Março 5, 2025.

  1. Stack

    Stack Membro Participativo

    There are occasions when I know ahead of time the full schema of a table I'm working with. In those scenarios, it would be nice to be able to specify the full schema (call it a FullyDefinedFrame). Then the type system could help me out with things like:

    1. error when accessing a column that doesn't exist
    2. type checking. E.g can't add a string column to an int column
    3. have it generate a new schema from an operation on a FullyDefinedFrame.
    4. Combine 1. and 3. to do, e.g. "you performed a pivot, and then accidentally accessed a column that doesn't exist anymore"

    I understand that polars does this at run time once it has the full schema of the data it's working on. But what if you could get all that information while still developing?

    At the moment, I imagine you could get a crummy version of this experience by having a tool that creates a dummy LazyFrame/DataFrame with the schema of the FullyDefinedFrame, and then call your functions on it, and give you the results.

    Is this possible in general? And if so, what would it take to make it work?

    Continue reading...

Compartilhe esta Página