Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repeat_by does not work with pl.lit #9815

Closed
2 tasks done
markxwang opened this issue Jul 11, 2023 · 3 comments
Closed
2 tasks done

repeat_by does not work with pl.lit #9815

markxwang opened this issue Jul 11, 2023 · 3 comments
Labels
bug Something isn't working python Related to Python Polars

Comments

@markxwang
Copy link
Contributor

markxwang commented Jul 11, 2023

Checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

pl.DataFrame({"a": [2, 3, 4]}).select(pl.lit("*").repeat_by(pl.col("a")))

Issue description

ComputeError: Length of repeat_by argument needs to be 1 or equal to the length of the Series. Series length 1, by length 3

Expected behavior

Expect to return a series of lists where the * literal is repeated by column a

Installed versions

--------Version info---------
Polars:      0.18.4
Index type:  UInt32
Platform:    macOS-13.3.1-arm64-arm-64bit
Python:      3.10.5 (main, Sep  6 2022, 09:52:19) [Clang 13.1.6 (clang-1316.0.21.2.5)]

----Optional dependencies----
numpy:       1.23.4
pandas:      2.0.0
pyarrow:     10.0.0
connectorx:  <not installed>
deltalake:   <not installed>
fsspec:      <not installed>
matplotlib:  3.6.2
xlsx2csv:    <not installed>
xlsxwriter:  <not installed>```

</details>
@markxwang markxwang added bug Something isn't working python Related to Python Polars labels Jul 11, 2023
@deanm0000
Copy link
Collaborator

This is intended. See #6360

To make it work as expected, create the column first like this:

(
    pl.DataFrame({"a": [2, 3, 4]})
        .with_columns(s=pl.lit('*'))
        .select(pl.col('s').repeat_by(pl.col('a')))
        )

@cmdlineluser
Copy link
Contributor

Just browsing old issues, this was implemented in #10735 and can be closed.

pl.DataFrame({"a": [2, 3, 4]}).select(pl.lit("*").repeat_by(pl.col("a")))

# shape: (3, 1)
# ┌───────────────────┐
# │ literal           │
# │ ---               │
# │ list[str]         │
# ╞═══════════════════╡
# │ ["*", "*"]        │
# │ ["*", "*", "*"]   │
# │ ["*", "*", … "*"] │
# └───────────────────┘

@romanovacca
Copy link
Contributor

@stinodego can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

5 participants