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

feat: Add mean_horizontal for temporal dtypes #20446

Closed
wants to merge 3 commits into from

Conversation

mcrumiller
Copy link
Contributor

@mcrumiller mcrumiller commented Dec 24, 2024

Closes #20313. Adds a path in mean_horizontal for temporals. A bit of logic update:

  1. Checks to ensure that if we have numeric columns, all columns are numeric (includes bool/null).
  2. Checks to ensure that if we have a temporal column, all columns have the same temporal dtype.

This implementation doesn't allow taking the mean of mixed time-unit dtypes that are otherwise the same. I am not sure if I should update logic to include this or not. In other words:

from datetime import datetime
import polars as pl

dates = [datetime(2025, 1, 1), datetime(2025, 1, 2)]

df = pl.DataFrame({
    "ms": pl.Series(dates, dtype=pl.Datetime(time_unit="ms")),
    "us1": pl.Series(dates, dtype=pl.Datetime(time_unit="us")),
    "us2": pl.Series(dates, dtype=pl.Datetime(time_unit="us")),
})

df.with_columns(
    pl.mean_horizontal("ms", "us1"),   # error--dtypes are not compatible
    pl.mean_horizontal("us1", "us2"),  # ok
)

@mcrumiller mcrumiller changed the title feat: feat: Add mean_horizontal for temporal dtypes Dec 24, 2024
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Dec 24, 2024
@mcrumiller mcrumiller closed this Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mean_horizontal raises on temporals
2 participants