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

Remove explicit references to Pandas in dask.dataframe.groupby #4778

Merged
merged 2 commits into from
May 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions dask/dataframe/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .core import (DataFrame, Series, aca, map_partitions,
new_dd_object, no_default, split_out_on_index,
_extract_meta)
from .methods import drop_columns
from .methods import drop_columns, concat
from .shuffle import shuffle
from .utils import (make_meta, insert_meta_param_description,
raise_on_meta_error, is_series_like, is_dataframe_like)
Expand Down Expand Up @@ -264,7 +264,7 @@ def _var_chunk(df, *index):
x2 = g2.sum().rename(columns=lambda c: c + '-x2')

x2.index = x.index
return pd.concat([x, x2, n], axis=1)
return concat([x, x2, n], axis=1)


def _var_combine(g, levels):
Expand Down Expand Up @@ -298,7 +298,7 @@ def _nunique_df_chunk(df, *index, **kwargs):

g = _groupby_raise_unaligned(df, by=index)
if len(df) > 0:
grouped = g[[name]].apply(pd.DataFrame.drop_duplicates)
grouped = g[[name]].apply(M.drop_duplicates)
# we set the index here to force a possibly duplicate index
# for our reduce step
if isinstance(levels, list):
Expand Down Expand Up @@ -671,7 +671,11 @@ def _groupby_apply_funcs(df, *index, **kwargs):
else:
result[result_column] = r

return pd.DataFrame(result)
if is_dataframe_like(df):
return type(df)(result)
else:
# Get the DataFrame type of this Series object
return type(df.head(0).to_frame())(result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type is this catching? Could you add a comment explaining what may show up here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to convert Series-like objects into DataFrames. I've added a comment in the latest commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Matt.



def _compute_sum_of_squares(grouped, column):
Expand All @@ -688,7 +692,7 @@ def _agg_finalize(df, aggregate_funcs, finalize_funcs, level):
for result_column, func, kwargs in finalize_funcs:
result[result_column] = func(df, **kwargs)

return pd.DataFrame(result)
return type(df)(result)


def _apply_func_to_column(df_like, column, func):
Expand Down