forked from lux-org/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LuxGroupby Implementation (lux-org#260)
* fix Record KeyError * add tests * take care of reset_index case * small edits * first implementation of groupby extended * add flag for groupby * update metadata lists * pre-agg impl + first pass on tests * 5 tests failing * 4 failing * fix failing tests with pre_aggregate * extend get_group and filter * fix final bug and add tests for groupby * fix get_axis_number bug and added default metadata values * remove unecessary computation * move history out of original df * add comments and consolidate metadata tests * add back cached datasets for tests * add clear_intent to tests Co-authored-by: Ujjaini Mukhopadhyay <[email protected]>
- Loading branch information
1 parent
144e8f7
commit e2ece28
Showing
18 changed files
with
283 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import pandas as pd | ||
|
||
|
||
class LuxDataFrameGroupBy(pd.core.groupby.generic.DataFrameGroupBy): | ||
|
||
_metadata = [ | ||
"_intent", | ||
"_inferred_intent", | ||
"_data_type", | ||
"unique_values", | ||
"cardinality", | ||
"_rec_info", | ||
"_min_max", | ||
"_current_vis", | ||
"_widget", | ||
"_recommendation", | ||
"_prev", | ||
"_history", | ||
"_saved_export", | ||
"_sampled", | ||
"_toggle_pandas_display", | ||
"_message", | ||
"_pandas_only", | ||
"pre_aggregated", | ||
"_type_override", | ||
] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(LuxDataFrameGroupBy, self).__init__(*args, **kwargs) | ||
|
||
def aggregate(self, *args, **kwargs): | ||
ret_val = super(LuxDataFrameGroupBy, self).aggregate(*args, **kwargs) | ||
for attr in self._metadata: | ||
ret_val.__dict__[attr] = getattr(self, attr, None) | ||
return ret_val | ||
|
||
def _agg_general(self, *args, **kwargs): | ||
ret_val = super(LuxDataFrameGroupBy, self)._agg_general(*args, **kwargs) | ||
for attr in self._metadata: | ||
ret_val.__dict__[attr] = getattr(self, attr, None) | ||
return ret_val | ||
|
||
def _cython_agg_general(self, *args, **kwargs): | ||
ret_val = super(LuxDataFrameGroupBy, self)._cython_agg_general(*args, **kwargs) | ||
for attr in self._metadata: | ||
ret_val.__dict__[attr] = getattr(self, attr, None) | ||
return ret_val | ||
|
||
def get_group(self, *args, **kwargs): | ||
ret_val = super(LuxDataFrameGroupBy, self).get_group(*args, **kwargs) | ||
for attr in self._metadata: | ||
ret_val.__dict__[attr] = getattr(self, attr, None) | ||
ret_val.pre_aggregated = False # Returned LuxDataFrame isn't pre_aggregated | ||
return ret_val | ||
|
||
def filter(self, *args, **kwargs): | ||
ret_val = super(LuxDataFrameGroupBy, self).filter(*args, **kwargs) | ||
for attr in self._metadata: | ||
ret_val.__dict__[attr] = getattr(self, attr, None) | ||
ret_val.pre_aggregated = False # Returned LuxDataFrame isn't pre_aggregated | ||
return ret_val | ||
|
||
def size(self, *args, **kwargs): | ||
ret_val = super(LuxDataFrameGroupBy, self).size(*args, **kwargs) | ||
for attr in self._metadata: | ||
ret_val.__dict__[attr] = getattr(self, attr, None) | ||
return ret_val | ||
|
||
def __getitem__(self, *args, **kwargs): | ||
ret_val = super(LuxDataFrameGroupBy, self).__getitem__(*args, **kwargs) | ||
for attr in self._metadata: | ||
ret_val.__dict__[attr] = getattr(self, attr, None) | ||
return ret_val | ||
|
||
agg = aggregate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.