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
4 changes: 4 additions & 0 deletions bodo/pandas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def head(self, n: int = 5):
assert self._head_df is not None
return self._head_df.head(0).copy()

# Negative n like -1 is equivalent to df.iloc[:-1]
if n < 0:
n = max(0, len(self) + n)

if (self._head_df is None) or (n > self._head_df.shape[0]):
if bodo.dataframe_library_enabled and isinstance(
self._mgr, LazyMetadataMixin
Expand Down
2 changes: 1 addition & 1 deletion bodo/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def head(self, n: int = 5):
if n < 0:
# Convert the negative number of the number not to include to a positive number so the rest of the
# code can run normally. Unfortunately, this will likely require a plan execution here.
n = self.shape[0] + n
n = max(0, len(self) + n)

if n == 0 and self._head_s is not None:
if self._exec_state == ExecState.COLLECTED:
Expand Down
Loading