-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Unexpected behavior when creating a new Series column with pl.date_range
#7110
Comments
I think you should ask a Stackoverflow question on how to get what you want to achieve. This doesn't seem a bug to me. |
Hello @ritchie46, I already solved what I wanted to achieve because my dataset has multiple entries, so no problem. But, the unexpected behavior appeared when I was debugging and using just one entry. I would expect the df = pl.DataFrame(
{
"name": ["A", "B", "C"],
"from": [1, 2, 3],
"to": [3, 4, 5],
}
)
# This works as expected for pl.arange:
(
df.limit(1)
.with_columns(
pl.arange(
low=pl.col("from"),
high=pl.col("to"),
step=1,
).alias("integers_range")
)
.explode("integers_range")
)
shape: (2, 4)
┌──────┬──────┬─────┬────────────────┐
│ name ┆ from ┆ to ┆ integers_range │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ i64 ┆ i64 │
╞══════╪══════╪═════╪════════════════╡
│ A ┆ 1 ┆ 3 ┆ 1 │
│ A ┆ 1 ┆ 3 ┆ 2 │
└──────┴──────┴─────┴────────────────┘ Using |
Right, I see the problem now. I will take a look later. |
I am also experiencing this issue in |
@wangkev I'm taking a look - for now you could use |
@MarcoGorelli we do something naive in the function where we see single value series as a different operation. This is wrong and we probably should break some behavior here. Let me know if you need anything from me. |
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
Creating a new Series column using
pl.date_range
works well if the DataFrame has a number of rows > 1. If the DataFrame has only one row, a ShapeError error is raised and the new column can not be added.Note:
using
pl.arange
to create a Series of integers works fine in both scenarios.with the current behavior of
pl.date_range
, it could limit using it inside agroupby
clause if the groups have a count of 1 row.Reproducible example
Expected behavior
Installed versions
The text was updated successfully, but these errors were encountered: