Skip to content

Commit

Permalink
Make slicing a series raise a not implemented error (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Dec 5, 2023
1 parent 2814bf1 commit 2f2c34f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dask_expr/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def __reduce__(self):
def __getitem__(self, other):
if isinstance(other, FrameBase):
return new_collection(self.expr.__getitem__(other.expr))
elif isinstance(other, slice):
return self.loc[other]
return new_collection(self.expr.__getitem__(other))

def persist(self, fuse=True, combine_similar=True, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion dask_expr/_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ def _meta(self):
if is_dataframe_like(self.frame._meta):
return super()._meta
# if we are not a DataFrame and have a scalar, we reduce to a scalar
if not isinstance(self.operand("columns"), list) and not hasattr(
if not isinstance(self.operand("columns"), (list, slice)) and not hasattr(
self.operand("columns"), "dtype"
):
return meta_nonempty(self.frame._meta).iloc[0]
Expand Down
5 changes: 5 additions & 0 deletions dask_expr/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,11 @@ def test_dropna_simplify(pdf, subset):
assert_eq(q, pdf.dropna(subset=subset)["y"])


def test_series_slice_getitem(df, pdf):
with pytest.raises(NotImplementedError):
df.x[:4]


def test_dir(df):
assert all(c in dir(df) for c in df.columns)
assert "sum" in dir(df)
Expand Down

0 comments on commit 2f2c34f

Please sign in to comment.