We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
In the documentation for keep_name, the output of the example is the same in the case where keep_name is not used and when it's used:
keep_name
Examples A groupby aggregation often changes the name of a column. With keep_name we can keep the original name of the column >>> df = pl.DataFrame( ... { ... "a": [1, 2, 3], ... "b": ["a", "b", None], ... } ... ) >>> df.groupby("a").agg(pl.col("b").list()).sort(by="a") shape: (3, 2) ┌─────┬───────────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ list[str] │ ╞═════╪═══════════╡ │ 1 ┆ ["a"] │ ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ │ 2 ┆ ["b"] │ ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ │ 3 ┆ [null] │ └─────┴───────────┘ Keep the original column name: >>> df.groupby("a").agg(pl.col("b").list().keep_name()).sort(by="a") shape: (3, 2) ┌─────┬───────────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ list[str] │ ╞═════╪═══════════╡ │ 1 ┆ ["a"] │ ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ │ 2 ┆ ["b"] │ ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ │ 3 ┆ [null] │ └─────┴───────────┘
A groupby aggregation often changes the name of a column. With keep_name we can keep the original name of the column
>>> df = pl.DataFrame( ... { ... "a": [1, 2, 3], ... "b": ["a", "b", None], ... } ... ) >>> df.groupby("a").agg(pl.col("b").list()).sort(by="a") shape: (3, 2) ┌─────┬───────────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ list[str] │ ╞═════╪═══════════╡ │ 1 ┆ ["a"] │ ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ │ 2 ┆ ["b"] │ ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ │ 3 ┆ [null] │ └─────┴───────────┘
Keep the original column name:
>>> df.groupby("a").agg(pl.col("b").list().keep_name()).sort(by="a") shape: (3, 2) ┌─────┬───────────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ list[str] │ ╞═════╪═══════════╡ │ 1 ┆ ["a"] │ ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ │ 2 ┆ ["b"] │ ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ │ 3 ┆ [null] │ └─────┴───────────┘
n/a
The example should show a change in behavior when keep_name is used. The first example needs to be a case whereby the column name changes.
I can't seem to find such an instance, but if someone wants to point me to an example where the column name changes, I can create a PR.
Replace this line with the output of pl.show_versions(), leave the backticks in place
The text was updated successfully, but these errors were encountered:
Right! Can you think of one? Maybe one where we do multicolumn arithmetic. (6 * pl.all()).keep_name()
(6 * pl.all()).keep_name()
Sorry, something went wrong.
Multi-column arithmetic doesn't seem to change the name either. A simple example would be something like:
df = pl.DataFrame({ 'a': [1, 2, 3, 4, 5] }) df.select(pl.col('a').alias('b'))
shape: (5, 1) ┌─────┐ │ b │ │ --- │ │ i64 │ ╞═════╡ │ 1 │ ├╌╌╌╌╌┤ │ 2 │ ├╌╌╌╌╌┤ │ 3 │ ├╌╌╌╌╌┤ │ 4 │ ├╌╌╌╌╌┤ │ 5 │ └─────┘
With keep_name:
df.select(pl.col('a').alias('b').keep_name())
shape: (5, 1) ┌─────┐ │ a │ │ --- │ │ i64 │ ╞═════╡ │ 1 │ ├╌╌╌╌╌┤ │ 2 │ ├╌╌╌╌╌┤ │ 3 │ ├╌╌╌╌╌┤ │ 4 │ ├╌╌╌╌╌┤ │ 5 │ └─────┘
However, it's not the greatest example.
See: #3773 (comment)
docs(python): Better docstring for keep_name (pola-rs#5378)
ef1d7ca
docs(python): Better docstring for keep_name (#5378) (#5421)
02b8114
No branches or pull requests
Polars version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Issue description
In the documentation for
keep_name
, the output of the example is the same in the case wherekeep_name
is not used and when it's used:Reproducible example
Expected behavior
The example should show a change in behavior when
keep_name
is used. The first example needs to be a case whereby the column name changes.I can't seem to find such an instance, but if someone wants to point me to an example where the column name changes, I can create a PR.
Installed versions
The text was updated successfully, but these errors were encountered: