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 and median for pl.Time should return a time #14470

Closed
2 tasks done
mcrumiller opened this issue Feb 13, 2024 · 0 comments · Fixed by #14471
Closed
2 tasks done

mean and median for pl.Time should return a time #14470

mcrumiller opened this issue Feb 13, 2024 · 0 comments · Fixed by #14471
Labels
bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@mcrumiller
Copy link
Contributor

mcrumiller commented Feb 13, 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

Part of #13599. mean and median either do not work, return null, or do not return the proper dtype, except in a groupby context.

from datetime import time
import polars as pl

s = pl.Series([time(hour=1), time(hour=2), time(hour=15)])
df = pl.DataFrame({
    "key": [1, 1, 1],
    "s": s
})

### Series

print(s.mean())
print(s.median())
print(s.dt.mean())    # errors
print(s.dt.median())  # errors
21600000000000.0
21600000000000.0
AttributeError: type object 'Time' has no attribute 'time_unit'

Frame

print(
    df.select(
        col("s").mean().alias("mean"),
        # col("s").median().alias("median")  ## errors
    )
)
shape: (1, 1)
┌──────┐
│ mean │
│ ---  │
│ time │
╞══════╡
│ null │
└──────┘

GroupBy

print(
    df.group_by("key").agg(
        col("s").mean().alias("mean"),
        col("s").median().alias("median")
    )
)
shape: (1, 3)
┌─────┬──────────┬──────────┐
│ key ┆ mean     ┆ median   │
│ --- ┆ ---      ┆ ---      │
│ i64 ┆ time     ┆ time     │
╞═════╪══════════╪══════════╡
│ 1   ┆ 06:00:00 ┆ 02:00:00 │
└─────┴──────────┴──────────┘

Installed versions

--------Version info---------
Polars:               0.20.7
Index type:           UInt32
Platform:             Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python:               3.12.1 (main, Jan 31 2024, 09:51:46) [GCC 11.4.0]

----Optional dependencies----
adbc_driver_manager:  0.9.0
cloudpickle:          3.0.0
connectorx:           <not installed>
deltalake:            0.15.2
fsspec:               2023.12.2
gevent:               23.9.1
hvplot:               0.9.2
matplotlib:           3.8.2
numpy:                1.26.4
openpyxl:             3.1.2
pandas:               2.2.0
pyarrow:              15.0.0
pydantic:             2.6.1
pyiceberg:            0.5.1
pyxlsb:               1.0.10
sqlalchemy:           2.0.25
xlsx2csv:             0.8.1
xlsxwriter:           3.1.9
@mcrumiller mcrumiller added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Feb 13, 2024
@stinodego stinodego added P-medium Priority: medium and removed needs triage Awaiting prioritization by a maintainer labels Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants