Skip to content

Commit

Permalink
ignore empty lists when dropping
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-quix committed Jul 16, 2024
1 parent eb5e1ac commit 8d42733
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions quixstreams/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,8 @@ def drop(self, columns: Union[str, List[str]]) -> Self:
:return: a new StreamingDataFrame instance
"""
if isinstance(columns, list):
if not columns:
return self
if not all(isinstance(s, str) for s in columns):
raise TypeError(f"column list must contain strings only")
elif isinstance(columns, str):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_quixstreams/test_dataframe/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ def test_drop_invalid_columns(self, dataframe_factory, columns):
with pytest.raises(TypeError):
sdf.drop(columns)

def test_drop_empty_list(self, dataframe_factory):
"""
Dropping an empty list is ignored entirely.
"""
sdf = dataframe_factory()
pre_drop_stream = sdf.stream.tree()
sdf = sdf.drop([])
post_drop_stream = sdf.stream.tree()
assert pre_drop_stream == post_drop_stream


class TestStreamingDataFrameApplyExpand:
def test_apply_expand(self, dataframe_factory):
Expand Down

0 comments on commit 8d42733

Please sign in to comment.