diff --git a/bodo/pandas/frame.py b/bodo/pandas/frame.py index f0f4723e99..85c8fa70cd 100644 --- a/bodo/pandas/frame.py +++ b/bodo/pandas/frame.py @@ -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 diff --git a/bodo/pandas/series.py b/bodo/pandas/series.py index c4025ecd2f..3d6be2dbb8 100644 --- a/bodo/pandas/series.py +++ b/bodo/pandas/series.py @@ -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: