Repository: modin-project/modin

Issue:
Operations with empty frame fail
When running smth like this 
`python -c "import modin.experimental.pandas as pd, modin.config as cfg; cfg.Engine.put('Ray'); cfg.Backend.put('OmniSci'); df = pd.DataFrame([]); (df + 1).shape"`

exception occurs:

```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/pandas/base.py", line 3031, in __getattribute__
    attr = super().__getattribute__(item)
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/pandas/dataframe.py", line 329, in shape
    return len(self.index), len(self.columns)
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/pandas/base.py", line 3031, in __getattribute__
    attr = super().__getattribute__(item)
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/pandas/base.py", line 573, in _get_index
    return self._query_compiler.index
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/experimental/backends/omnisci/query_compiler.py", line 446, in _get_index
    return self._modin_frame.index
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/experimental/engines/omnisci_on_ray/frame/data.py", line 1907, in _get_index
    self._execute()
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/experimental/engines/omnisci_on_ray/frame/data.py", line 1699, in _execute
    new_table = self._execute_arrow()
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/experimental/engines/omnisci_on_ray/frame/data.py", line 1785, in _execute_arrow
    return self._op.input[0]._arrow_col_slice(set(self._op.exprs.keys()))
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/experimental/engines/omnisci_on_ray/frame/data.py", line 1805, in _arrow_col_slice
    table = self._execute_arrow()
  File "/localdisk/izamyati/miniconda3/envs/modintest112/lib/python3.9/site-packages/modin/experimental/engines/omnisci_on_ray/frame/data.py", line 1778, in _execute_arrow
    return pyarrow.Table()
  File "pyarrow/table.pxi", line 1139, in pyarrow.lib.Table.__init__
TypeError: Do not call Table's constructor directly, use one of the `Table.from_*` functions instead.
```

Looks like smth wrong with empty frame


Discussion:
cc @ienkovich @dchigarev 
@Garra1980 is this only with Omnisci?
Yes

Resolving patch:
diff --git a/modin/experimental/engines/omnisci_on_native/frame/data.py b/modin/experimental/engines/omnisci_on_native/frame/data.py
--- a/modin/experimental/engines/omnisci_on_native/frame/data.py
+++ b/modin/experimental/engines/omnisci_on_native/frame/data.py
@@ -1696,7 +1696,7 @@ def _execute_arrow(self):
         """
         if isinstance(self._op, FrameNode):
             if self._partitions.size == 0:
-                return pyarrow.Table()
+                return pyarrow.Table.from_pandas(pd.DataFrame({}))
             else:
                 assert self._partitions.size == 1
                 return self._partitions[0][0].get()
@@ -2397,6 +2397,8 @@ def _is_trivial_index(cls, index):
         -------
         bool
         """
+        if len(index) == 0:
+            return True
         if isinstance(index, pd.RangeIndex):
             return index.start == 0 and index.step == 1
         if not isinstance(index, pd.Int64Index):


Test patch:
diff --git a/modin/experimental/engines/omnisci_on_native/test/test_dataframe.py b/modin/experimental/engines/omnisci_on_native/test/test_dataframe.py
--- a/modin/experimental/engines/omnisci_on_native/test/test_dataframe.py
+++ b/modin/experimental/engines/omnisci_on_native/test/test_dataframe.py
@@ -2000,6 +2000,12 @@ def drop_rename_concat(df1, df2, lib, **kwargs):
             force_arrow_execute=True,
         )
 
+    def test_empty_transform(self):
+        def apply(df, **kwargs):
+            return df + 1
+
+        run_and_compare(apply, data={}, force_arrow_execute=True)
+
 
 if __name__ == "__main__":
     pytest.main(["-v", __file__])