Giter Site home page Giter Site logo

Comments (5)

cmdlineluser avatar cmdlineluser commented on May 29, 2024 1

The int version working seems a bit odd because 4 is being "replaced" by [4]

I did notice that forcing the default value is possible:

df_str.select(
   pl.col("a").list.eval(
      pl.element().replace({"1": ["11", "111"], "2": ["22"]}, default=pl.concat_list(pl.element()))
   )
)

# shape: (1, 1)
# ┌────────────────────────────────┐
# │ a                              │
# │ ---                            │
# │ list[list[str]]                │
# ╞════════════════════════════════╡
# │ [["11", "111"], ["22"], ["4"]] │
# └────────────────────────────────┘

from polars.

moritzwilksch avatar moritzwilksch commented on May 29, 2024

ahh i figured that happens to force a consistent datatype. Neat workaround with the default though!

from polars.

ThomasMAhern avatar ThomasMAhern commented on May 29, 2024

I too am hoping for this to be resolved!

from polars.

cmdlineluser avatar cmdlineluser commented on May 29, 2024

@ThomasMAhern What do you need resolved?

It seems that both examples should raise here and the fact that the int case works is a "bug"?

EDIT: Ah, the return_dtype docs say: "the data type is determined automatically based on the other inputs" - so perhaps I am mistaken.


Just experimenting further, something else seems broken:

df_int.with_columns(
   a1 = pl.col("a").list.eval(pl.element().replace("1", [["a", "b"]]))
)

# shape: (1, 2)
# ┌───────────┬────────────────────────────┐
# │ a         ┆ a1                         │
# │ ---       ┆ ---                        │
# │ list[i64] ┆ list[list[str]]            │
# ╞═══════════╪════════════════════════════╡
# │ [1, 2, 4] ┆ [["a", "b"], ["2"], ["4"]] │
# └───────────┴────────────────────────────┘

1 is being cast to "1" then the replace succeeds?

from polars.

ThomasMAhern avatar ThomasMAhern commented on May 29, 2024

It seems I'm able to get the expected output if I specify return_dtype=pl.List(pl.String)

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.