-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Optimization for heatmap aggregation with pandas #1174
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,13 @@ | |
|
||
from ..core import Dataset, OrderedDict | ||
from ..core.operation import ElementOperation | ||
from ..core.util import (pd, is_nan, sort_topologically, | ||
cartesian_product, is_cyclic, one_to_one) | ||
from ..core.util import (is_nan, sort_topologically, one_to_one, | ||
cartesian_product, is_cyclic, get_df_data) | ||
|
||
try: | ||
import pandas as pd | ||
except: | ||
pd = None | ||
|
||
try: | ||
import dask | ||
|
@@ -134,7 +139,13 @@ def _aggregate_dataset(self, obj, xcoords, ycoords): | |
dtype = 'dataframe' if pd else 'dictionary' | ||
dense_data = Dataset(data, kdims=obj.kdims, vdims=obj.vdims, datatype=[dtype]) | ||
concat_data = obj.interface.concatenate([dense_data, obj], datatype=[dtype]) | ||
agg = concat_data.reindex([xdim, ydim], vdims).aggregate([xdim, ydim], reduce_fn) | ||
reindexed = concat_data.reindex([xdim, ydim], vdims) | ||
if pd: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose the other thing you could do is complain if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because then I need conditional branches for the "is already dataframe" and "convert to dataframe" paths again. I guess I agree There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would there be any harm with the dataframe interfaces just avoiding pointless copies automatically? Then it doesn't have to be something the user needs to ever think about... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my usage of dframe I often create it and then assign to it so that would be a bit of pain. |
||
df = reindexed.dframe(copy=False) | ||
df = df.groupby([xdim, ydim], sort=False).first().reset_index() | ||
agg = reindexed.clone(df) | ||
else: | ||
agg = reindexed.aggregate([xdim, ydim], reduce_fn) | ||
|
||
# Convert data to a gridded dataset | ||
grid_data = {xdim: xcoords, ydim: ycoords} | ||
|
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.
I'm not sure copy argument makes much sense if the element isn't already using a dataframe based interface - for other interfaces, don't you always have to create a new dataframe - which would be the same as
copy
being fixed toTrue
?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.
That's true, it's more like
avoid_copy
, but I think providing a consistent API to get a hold of a dataframe with the minimal amount of overhead is useful.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.
That said, I'd also be fine having a utility for it instead.