[BUG] `IndexedFrame._split` is inconsistent for empty dataframes
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.1k
- Avg merge
- 3d 6m
- Merged PRs (30d)
- 278
Description
This came up while reviewing #12704.
Quoth the documentation:
> Split a frame with split points in ``splits``. Returns a list of Frames of length `len(splits) + 1`.
Which is true, except if the input dataframe is empty:
```python
import cudf
df = cudf.DataFrame({"a": []})
print(df._split([0])) # => []
```
This makes writing generic code difficult, since we're expecting to get back a list of N+1 things to iterate over, but in this case we don't.
Slicing empty dataframes works fine (and reproduces semantically what you "expect" from slicing empty python lists):
```python
df[:0], df[0:] # => (Empty DataFrame, Empty DataFrame)
```
(Arguably slicing with an out of bounds index should raise an `IndexError`, but that ship has sailed.)
What I would like:
```python
splits = [...]
assert df._split(splits) == [df[s:e] for s, e in zip([None] + splits, splits + [None])]
```
Contributor guide
Assessment
This issue has not been assessed yet.