You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resample is ~100x slower than Pandas resample; Speed is related to resample period (unlike Pandas) #4498
I have a 10 minute frequency time series. When I resample to hourly it is slow. When I resample to daily it is fast. If I drop to Pandas and resample the speeds are ~100x faster than xarray, and also the same time regardless of the resample period. I've posted this to SO: https://stackoverflow.com/questions/64282393/
What you expected to happen:
I expect xarray to be within an order of magnitude speed of Pandas, not > 2 orders of magnitude slower.
"performance" is a good tag. My actual use case is a dataset with 500,000 timestamps and 15 variables (10 minute weather station for a decade).
In this case, pandas takes 0.03 seconds, and xarray takes 200 seconds. 4 orders of magnitude. Should I change the title to reflect the larger difference in performance? Here is that MWE:
I might add that this is somewhat I've wanted to speed-up in xarray since the very early days. But until I noticed the numpy-groupies package, it seemed like a pretty challenging task.
Thanks for the clarification that this is a real issue not due to just my coding, and the suggestion to solve this elsewhere. For now I just use the fast Pandas version with this code:
df_h=ds.to_dataframe().resample("1H").mean() # what we want (quickly), but in Pandas formvals= [xr.DataArray(data=df_h[c], dims=['time'], coords={'time':df_h.index}, attrs=ds[c].attrs) forcindf_h.columns]
ds_h=xr.Dataset(dict(zip(df_h.columns,vals)), attrs=ds.attrs)
The linked issues refer to groupby not resample so this could stay open or be closed as a duplicate - I leave it to you to decide. Thank you for the assistance.
Activity
dcherian commentedon Oct 9, 2020
@mankoff (hi!) This is interesting. If I comment out
.mean()I geti.e. we are 2x slower just on factorizing.
mankoff commentedon Oct 10, 2020
"performance" is a good tag. My actual use case is a dataset with 500,000 timestamps and 15 variables (10 minute weather station for a decade).
In this case, pandas takes 0.03 seconds, and xarray takes 200 seconds. 4 orders of magnitude. Should I change the title to reflect the larger difference in performance? Here is that MWE:
Result:
The strange thing here is if I drop the
.mean()'s, most of the time I see what you see.But every 4th or 5th time that I run this, I get this:
This is repeatable. I've Run this code 100s of times now, and every 4th or 5th run it takes 10x. Nothing else is going on on my computer.
mankoff commentedon Oct 10, 2020
The every 4th or 5th lag is not in the creation, it's in the
resample:shoyer commentedon Oct 11, 2020
resampleuses the same machinery in xarray as other grouped aggregations.Right now, grouped aggregations are very slow when there are many groups (like in resample) because we use a Python loop over groups.
Probably the most obvious way to speed this up would be to wrap the "numpy-groupies" package in xarray: #4473
shoyer commentedon Oct 11, 2020
I might add that this is somewhat I've wanted to speed-up in xarray since the very early days. But until I noticed the numpy-groupies package, it seemed like a pretty challenging task.
mankoff commentedon Oct 11, 2020
Thanks for the clarification that this is a real issue not due to just my coding, and the suggestion to solve this elsewhere. For now I just use the fast Pandas version with this code:
mankoff commentedon Oct 11, 2020
The linked issues refer to
groupbynotresampleso this could stay open or be closed as a duplicate - I leave it to you to decide. Thank you for the assistance.Fast resample using Pandas
Enable `flox` in `GroupBy` and `resample` (pydata#5734)
Enable `flox` in `GroupBy` and `resample` (pydata#5734)
Enable flox in GroupBy and resample (pydata#5734)