-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: groupby reductions with pyarrow dtypes #52469
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
Conversation
Thanks @jbrockmendel |
|
||
mask = self.isna() | ||
arr = self.to_numpy(dtype=np_dtype, na_value=na_value) | ||
return arr_cls(arr, mask) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment on the issue, I think this can be optimized and simplified by reusing __from_arrow__
(which uses pyarrow_array_to_numpy_and_mask
under the hood)
There still is huge performance degradation in pandas 2.0.3: import numpy as np
import pandas as pd
M, N = 10, 10_000
tol = 0.5
y = np.random.rand(N, M)
y[y > tol] = float("nan")
df = pd.DataFrame(y, dtype="float32[pyarrow]")
df.index.name = "time" %%time
df.convert_dtypes(dtype_backend="numpy_nullable").groupby("time").mean() finishes in 13.2 ms %%time
df.groupby("time").mean() takes 4.42 s (!) I noticed this when I tried aggregating a timeseries with duplicate index entries. But it also happens when grouping by a column. |
I don't see anything close to 4.42s
|
Strange. this is my environment
I will try on another machine when I'm home. |
I could reproduce it on my desktop as well. Both machines run Ubuntu 22.04, desktop CPU: AMD 3900X, Laptop CPU: i7-11800H. Tried both python 3.10 and 3.11. |
I was able to reproduce it in google-colab as well: https://colab.research.google.com/drive/1kZVSEmLOWXGLV8uRvrc2ACFXdiqoq0cd?usp=sharing |
Should I open a separate issue for this? |
Sure, let's see if anyone else can reproduce |
Opened #54208 |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Re-running the benchmark in #52070
The _to_masked conversion constitutes about 2/3 of the runtime of the _groupby_op call, so there is still room for improvement. (Though the .sum() is only about 1/3 of the total runtime here)