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

mean_horizontal raises on temporals #20313

Open
2 tasks done
mcrumiller opened this issue Dec 16, 2024 · 0 comments · May be fixed by #20522
Open
2 tasks done

mean_horizontal raises on temporals #20313

mcrumiller opened this issue Dec 16, 2024 · 0 comments · May be fixed by #20522
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@mcrumiller
Copy link
Contributor

mcrumiller commented Dec 16, 2024

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

mean and median are well-defined on all temporals, but mean_horizontal and median_horizontal are not.

from datetime import date
import polars as pl

df = pl.DataFrame({
    "a": [date(2024, 1, 1), date(2024, 2, 1)],
    "b": [date(2024, 1, 2), date(2024, 2, 2)],
})
# shape: (2, 2)
# ┌────────────┬────────────┐
# │ a          ┆ b          │
# │ ---        ┆ ---        │
# │ date       ┆ date       │
# ╞════════════╪════════════╡
# │ 2024-01-01 ┆ 2024-01-02 │
# │ 2024-02-01 ┆ 2024-02-02 │
# └────────────┴────────────┘

# Regular mean: works
df.select(
    pl.all().mean().name.suffix("_mean"),
)
# shape: (1, 2)
# ┌─────────────────────┬─────────────────────┐
# │ a_mean              ┆ b_mean              │
# │ ---                 ┆ ---                 │
# │ datetime[ms]        ┆ datetime[ms]        │
# ╞═════════════════════╪═════════════════════╡
# │ 2024-01-16 12:00:00 ┆ 2024-01-17 12:00:00 │
# └─────────────────────┴─────────────────────┘

# Mean horizontal: error
df.select(
    pl.mean_horizontal("a", "b").alias("mean")
)
# polars.exceptions.InvalidOperationError: 'horizontal_mean' expects numeric expressions, found "a" (dtype=date)

Installed versions

main

@mcrumiller mcrumiller added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Dec 16, 2024
@mcrumiller mcrumiller linked a pull request Jan 2, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
1 participant