-
Notifications
You must be signed in to change notification settings - Fork 0
Implement multiple axis for dropna #13
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
Changes from 3 commits
9c4e2b1
b6403f4
666860c
582f628
f9e14e7
fed275e
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 |
|---|---|---|
|
|
@@ -776,9 +776,20 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None, | |
| DataFrame with the dropna applied. | ||
| """ | ||
| if is_list_like(axis): | ||
| raise NotImplementedError( | ||
| "To contribute to Pandas on Ray, please visit " | ||
| "github.com/ray-project/ray.") | ||
| axis = set([pd.DataFrame()._get_axis_number(ax) for ax in axis]) | ||
| result = self | ||
|
Owner
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. unnecessary
Author
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 think it is necessary in this case b/c the for loop makes reference to |
||
| for ax in axis: | ||
|
Owner
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. Add a comment here that this is inefficient since it forces the DataFrame to be built as an intermediate and should be fixed later. |
||
| result = result.dropna( | ||
| axis=ax, how=how, thresh=thresh, subset=subset) | ||
| if not inplace: | ||
| return result | ||
|
|
||
| return self._update_inplace( | ||
|
Owner
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. Pass
Author
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. done! |
||
| row_partitions=result._row_partitions, | ||
| col_partitions=result._col_partitions, | ||
| columns=result._col_metadata.index, | ||
|
||
| index=result._row_metadata.index | ||
|
||
| ) | ||
|
|
||
| axis = pd.DataFrame()._get_axis_number(axis) | ||
| inplace = validate_bool_kwarg(inplace, "inplace") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -839,6 +839,7 @@ def test_dense_nan_df(): | |
|
|
||
| test_dropna(ray_df, pd_df) | ||
| test_dropna_inplace(ray_df, pd_df) | ||
| test_dropna_multiple_axes(ray_df, pd_df) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
|
@@ -1297,16 +1298,17 @@ def test_drop_duplicates(): | |
|
|
||
| @pytest.fixture | ||
| def test_dropna(ray_df, pd_df): | ||
| ray_df_equals_pandas(ray_df.dropna(axis=1, how='all'), | ||
| pd_df.dropna(axis=1, how='all')) | ||
| assert ray_df_equals_pandas(ray_df.dropna(axis=1, how='all'), | ||
| pd_df.dropna(axis=1, how='all')) | ||
|
|
||
| ray_df_equals_pandas(ray_df.dropna(axis=1, how='any'), | ||
| pd_df.dropna(axis=1, how='any')) | ||
| assert ray_df_equals_pandas(ray_df.dropna(axis=1, how='any'), | ||
|
Owner
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. Great catch, thanks! |
||
| pd_df.dropna(axis=1, how='any')) | ||
|
|
||
| ray_df_equals_pandas(ray_df.dropna(axis=0, how='all'), | ||
| pd_df.dropna(axis=0, how='all')) | ||
| assert ray_df_equals_pandas(ray_df.dropna(axis=0, how='all'), | ||
| pd_df.dropna(axis=0, how='all')) | ||
|
|
||
| ray_df_equals_pandas(ray_df.dropna(thresh=2), pd_df.dropna(thresh=2)) | ||
| assert ray_df_equals_pandas(ray_df.dropna(thresh=2), | ||
| pd_df.dropna(thresh=2)) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
|
@@ -1317,12 +1319,33 @@ def test_dropna_inplace(ray_df, pd_df): | |
| ray_df.dropna(thresh=2, inplace=True) | ||
| pd_df.dropna(thresh=2, inplace=True) | ||
|
|
||
| ray_df_equals_pandas(ray_df, pd_df) | ||
| assert ray_df_equals_pandas(ray_df, pd_df) | ||
|
|
||
| ray_df.dropna(axis=1, how='any', inplace=True) | ||
| pd_df.dropna(axis=1, how='any', inplace=True) | ||
|
|
||
| ray_df_equals_pandas(ray_df, pd_df) | ||
| assert ray_df_equals_pandas(ray_df, pd_df) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def test_dropna_multiple_axes(ray_df, pd_df): | ||
| ray_df = ray_df.copy() | ||
|
||
| pd_df = pd_df.copy() | ||
| cp = ray_df.copy() | ||
| result = ray_df.dropna(how='all', axis=[0, 1]) | ||
| result2 = ray_df.dropna(how='all', axis=(0, 1)) | ||
| expected = pd_df.dropna(how='all').dropna(how='all', axis=1) | ||
|
||
|
|
||
| assert ray_df_equals_pandas(result, expected) | ||
| assert ray_df_equals_pandas(result2, expected) | ||
|
|
||
| assert ray_df_equals_pandas(result, expected) | ||
|
||
| assert ray_df_equals_pandas(result2, expected) | ||
| assert ray_df_equals(ray_df, cp) | ||
|
|
||
| inp = ray_df.copy() | ||
|
||
| inp.dropna(how='all', axis=(0, 1), inplace=True) | ||
| assert ray_df_equals_pandas(inp, expected) | ||
|
||
|
|
||
|
|
||
| def test_duplicated(): | ||
|
|
||
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.
Don't put it in a set here.