Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions python/ray/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
result = self
# TODO(kunalgosar): this builds an intermediate dataframe,
# which does unnecessary computation
for ax in axis:
result = result.dropna(
axis=ax, how=how, thresh=thresh, subset=subset)
if not inplace:
return result

return self._update_inplace(
Copy link
Owner

Choose a reason for hiding this comment

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

Pass _block_partitions in instead, it's more efficient.

Copy link
Author

Choose a reason for hiding this comment

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

done!

block_partitions=result._block_partitions,
columns=result.columns,
index=result.index
)

axis = pd.DataFrame()._get_axis_number(axis)
inplace = validate_bool_kwarg(inplace, "inplace")
Expand Down
52 changes: 43 additions & 9 deletions python/ray/dataframe/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ 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)
test_dropna_multiple_axes_inplace(ray_df, pd_df)


@pytest.fixture
Expand Down Expand Up @@ -1297,16 +1299,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'),
Copy link
Owner

Choose a reason for hiding this comment

The 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
Expand All @@ -1317,12 +1320,43 @@ 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):
assert ray_df_equals_pandas(
ray_df.dropna(how='all', axis=[0, 1]),
pd_df.dropna(how='all', axis=[0, 1])
)
assert ray_df_equals_pandas(
ray_df.dropna(how='all', axis=(0, 1)),
pd_df.dropna(how='all', axis=(0, 1))
)


@pytest.fixture
def test_dropna_multiple_axes_inplace(ray_df, pd_df):
ray_df_copy = ray_df.copy()
pd_df_copy = pd_df.copy()

ray_df_copy.dropna(how='all', axis=[0, 1], inplace=True)
pd_df_copy.dropna(how='all', axis=[0, 1], inplace=True)

assert ray_df_equals_pandas(ray_df_copy, pd_df_copy)

ray_df_copy = ray_df.copy()
pd_df_copy = pd_df.copy()

ray_df_copy.dropna(how='all', axis=(0, 1), inplace=True)
pd_df_copy.dropna(how='all', axis=(0, 1), inplace=True)

assert ray_df_equals_pandas(ray_df_copy, pd_df_copy)


def test_duplicated():
Expand Down