Giter VIP home page Giter VIP logo

Comments (3)

kevinli1993 avatar kevinli1993 commented on June 28, 2024

This seems to have something to do with setting upper_bound.

The documentation states:

When operating on a DataFrame, the schema does not need to be tracked or pre-determined, as the result will be eagerly evaluated, so you can leave this parameter unset.

but it does seem to have an effect even in eager mode:

ds.select(pl.col("A").list.to_struct(upper_bound=3).struct.field("*"))  # Works now!
shape: (3, 3)
┌─────────┬─────────┬─────────┐
│ field_0 ┆ field_1 ┆ field_2 │
│ ---     ┆ ---     ┆ ---     │
│ str     ┆ str     ┆ str     │
╞═════════╪═════════╪═════════╡
│ A       ┆ B       ┆ C       │
│ D       ┆ null    ┆ null    │
│ E       ┆ F       ┆ null    │
└─────────┴─────────┴─────────┘

However, it seems like I need to "correctly" guess the number of upper_bound, e.g. this will break:

ds.select(pl.col("A").list.to_struct(upper_bound=999).struct.field("*"))

StructFieldNotFoundError: field_272

(and in fact, the "272" in field_272 is random, it's different each time. Probably due to parallelism).

from polars.

ritchie46 avatar ritchie46 commented on June 28, 2024

This cannot be solved dynamically. Polars needs to know the data-type before running the query on the actual data. So if your upper bound is incorrect, Polars will expand fields that don't exist in the data.

There is not much we can do here.

from polars.

kevinli1993 avatar kevinli1993 commented on June 28, 2024

Ah I see - it's a consequence of LazyFrame in that ds.with_columns(...) has similar semantics as ds.lazy().with_columns(...).collect()

from polars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.