Giter Site home page Giter Site logo

Comments (8)

herrmann1981 avatar herrmann1981 commented on August 19, 2024 1

Interestingly from your above example this fails:

lf_result.sink_parquet("lazy_frame.parquet")

But this succeeds:

lf_result.collect().lazy().sink_parquet("lazy_frame.parquet")

from polars.

herrmann1981 avatar herrmann1981 commented on August 19, 2024 1

@cmdlineluser Thanks for your feedback. When I specify the full schema then streaming works for me. Also my complete use case not only the example above.
Problem is solved for me.

from polars.

jpfeuffer avatar jpfeuffer commented on August 19, 2024 1

Sorry, but this cannot be the solution. What if you have an unknown amount of fields that are inferred by polars in the unnest function.
You cannot specify a schema in that case without replicating the inference process of polars.
This is an obvious bug to me and IMHO should be reopened.

from polars.

coastalwhite avatar coastalwhite commented on August 19, 2024

This might be very well be caused by #16274 and fixed by #16463.

EDIT: nevermind, this is not related to that at all

from polars.

cmdlineluser avatar cmdlineluser commented on August 19, 2024

I'm not sure if it is the underlying cause, but whilst trying to reduce down your example, the sink_parquet panics:

import polars as pl

lf = pl.LazyFrame({
    "index": [0, 1, 2],
    "payload": [1, 1, 1],
    "category": ["a", "b", "c"]
})

lf_temp = (
    lf.with_columns(
        pl.struct("index", "payload", "category").map_elements(lambda row: 
            [
                {"a": row["index"], "b": row["payload"], "c": row["category"]},
                {"a": row["index"] + 1, "b": row["payload"] + 1, "c": row["category"]}
            ],
            return_dtype=pl.List(pl.Struct)
        )
        .alias("struct_column")
    )
)

lf_result = lf_temp.explode("struct_column").unnest("struct_column")

lf_result.sink_parquet("lazy_frame.parquet")
# pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: 
# ComputeError(ErrString("a StructArray must contain at least one field"))

The .collect() output looks OK:

shape: (6, 6)
┌───────┬─────────┬──────────┬─────┬─────┬─────┐
│ indexpayloadcategoryabc   │
│ ------------------ │
│ i64i64stri64i64str │
╞═══════╪═════════╪══════════╪═════╪═════╪═════╡
│ 01a01a   │
│ 01a12a   │
│ 11b11b   │
│ 11b22b   │
│ 21c21c   │
│ 21c32c   │
└───────┴─────────┴──────────┴─────┴─────┴─────┘

from polars.

cmdlineluser avatar cmdlineluser commented on August 19, 2024

Yeah, the collect also panics with streaming enabled:

lf_result.collect(streaming=True)

# PanicException: called `Result::unwrap()` on an `Err` value: 
# ComputeError(ErrString("a StructArray must contain at least one field"))

from polars.

cmdlineluser avatar cmdlineluser commented on August 19, 2024

I just tried this again on the latest main and it still fails.

Specifying the full schema allows it to run as expected.

return_dtype=pl.List(pl.Struct({'a': pl.Int64, 'b': pl.Int64, 'c': pl.String}))

It seems allowing an empty pl.Struct leads to the problem here?

from polars.

jpfeuffer avatar jpfeuffer commented on August 19, 2024

@cmdlineluser Thank you for reopening 🙏🏻 or linking

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.