Repository: modin-project/modin

Issue:
BUG: HDK: DataFrame.iloc with a wide range causes SIGSEGV
### Modin version checks

- [X] I have checked that this issue has not already been reported.

- [X] I have confirmed this bug exists on the latest released version of Modin.

- [X] I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow [this guide](https://modin.readthedocs.io/en/stable/getting_started/installation.html#installing-from-the-github-master-branch).)


### Reproducible Example

```python
import modin.pandas as pd

df = pd.DataFrame({"A": range(1000000)})
df = df.iloc[:1000000].dropna()
print(df)
```


### Issue Description

The code above fails with SIGSEGV. The root cause of the failure - a huge query, sent to HDK. The query is so big, because it contains an enumeration of all possible column values, i.e.: (col == 0) || (col == 1) .... (col == 999999).

### Expected Behavior

The query must be simplified to 0 <= col <= 999999.

### Error Logs

<details>

```python-traceback

Replace this line with the error backtrace (if applicable).

```

</details>


### Installed Versions

<details>

Replace this line with the output of pd.show_versions()

</details>



Discussion:

Resolving patch:
diff --git a/modin/experimental/core/execution/native/implementations/hdk_on_native/expr.py b/modin/experimental/core/execution/native/implementations/hdk_on_native/expr.py
--- a/modin/experimental/core/execution/native/implementations/hdk_on_native/expr.py
+++ b/modin/experimental/core/execution/native/implementations/hdk_on_native/expr.py
@@ -14,6 +14,8 @@
 """Module provides classes for scalar expression trees."""
 
 import abc
+
+import pandas as pd
 from pandas.core.dtypes.common import (
     is_list_like,
     get_dtype,
@@ -183,10 +185,7 @@ def eq(self, other):
         BaseExpr
             The resulting comparison expression.
         """
-        if not isinstance(other, BaseExpr):
-            other = LiteralExpr(other)
-        new_expr = OpExpr("=", [self, other], get_dtype(bool))
-        return new_expr
+        return self.cmp("=", other)
 
     def le(self, other):
         """
@@ -197,6 +196,40 @@ def le(self, other):
         other : BaseExpr or scalar
             An operand to compare with.
 
+        Returns
+        -------
+        BaseExpr
+            The resulting comparison expression.
+        """
+        return self.cmp("<=", other)
+
+    def ge(self, other):
+        """
+        Build a greater or equal comparison with `other`.
+
+        Parameters
+        ----------
+        other : BaseExpr or scalar
+            An operand to compare with.
+
+        Returns
+        -------
+        BaseExpr
+            The resulting comparison expression.
+        """
+        return self.cmp(">=", other)
+
+    def cmp(self, op, other):
+        """
+        Build a comparison expression with `other`.
+
+        Parameters
+        ----------
+        op : str
+            A comparison operation.
+        other : BaseExpr or scalar
+            An operand to compare with.
+
         Returns
         -------
         BaseExpr
@@ -204,8 +237,7 @@ def le(self, other):
         """
         if not isinstance(other, BaseExpr):
             other = LiteralExpr(other)
-        new_expr = OpExpr("<=", [self, other], get_dtype(bool))
-        return new_expr
+        return OpExpr(op, [self, other], get_dtype(bool))
 
     def cast(self, res_type):
         """
@@ -850,13 +882,12 @@ def build_row_idx_filter_expr(row_idx, row_col):
     if not is_list_like(row_idx):
         return row_col.eq(row_idx)
 
-    exprs = []
-    for idx in row_idx:
-        exprs.append(row_col.eq(idx))
+    if isinstance(row_idx, (pd.RangeIndex, range)) and row_idx.step == 1:
+        exprs = [row_col.ge(row_idx[0]), row_col.le(row_idx[-1])]
+        return OpExpr("AND", exprs, get_dtype(bool))
 
-    res = OpExpr("OR", exprs, get_dtype(bool))
-
-    return res
+    exprs = [row_col.eq(idx) for idx in row_idx]
+    return OpExpr("OR", exprs, get_dtype(bool))
 
 
 def build_if_then_else(cond, then_val, else_val, res_type):


Test patch:
diff --git a/modin/experimental/core/execution/native/implementations/hdk_on_native/test/test_dataframe.py b/modin/experimental/core/execution/native/implementations/hdk_on_native/test/test_dataframe.py
--- a/modin/experimental/core/execution/native/implementations/hdk_on_native/test/test_dataframe.py
+++ b/modin/experimental/core/execution/native/implementations/hdk_on_native/test/test_dataframe.py
@@ -2424,6 +2424,16 @@ def test_iloc_int(self):
         pds = pandas.Series(data[next(iter(data.keys()))]).iloc[1:]
         df_equals(mds, pds)
 
+    def test_iloc_issue_6037(self):
+        def iloc(df, **kwargs):
+            return df.iloc[:-1].dropna()
+
+        run_and_compare(
+            fn=iloc,
+            data={"A": range(1000000)},
+            force_lazy=False,
+        )
+
 
 class TestStr:
     def test_str(self):