Repository: modin-project/modin

Issue:
"ValueError: Invalid integer data type 'f'." when doing `loc` on empty dataframe
We currently default to pandas when we're operating on empty dataframes, but this doesn't happen for some properties. `loc` will fail if you try to use it on an empty dataframe.

Reproduction script:

```python
import modin.pandas as pd
import ray
import pandas_market_calendars as mcal
from pandas.tseries.offsets import BusinessDay

import datetime as dt
ENTITIES = ['037833100', '594918104', '023135106', '30231G102', '478160104', '30303M102', '369604103', '00206R102',
          '46625H100', '742718109', '02079K305', '949746101', '931142103', '92343V104', '717081103', '084670702',
          '166764100', '191216100', '458140100', '58933Y105', '68389X105', '060505104', '20030N101', '437076102',
          '92826C839', '17275R102', '718172109', '713448108', '254687106', '459200101', '172967424', '91324P102',
          '031162100', '02209S103', '57636Q104', '88579Y101', '500754106', '806857108', '375558103', '00287Y109',
          '580135101', '126650100', '747525103', '110122108', '931427108', '532457108', '438516106', '913017109',
          '151020104', '097023105', '855244109', '907818108', '654106103', '911312106', '902973304', '741503403',
          '16119P108', '539830109', '882508104', '761713106', 'Y09827109', '38141G104', '609207105', '09062X103',
          '22160K105', '828806109', '194162103', '548661107', '026874784', '002824100', '617446448', '09247X101',
          '260543103', '025816109', '883556102', '887317303', '263534109', '65339F101', '293792107', '26441C204',
          '674599105', '235851102', '842587107', '00724F101', '26875P101', '37045V100', '79466L302', '872540109',
            '49456B101', '20825C104', '59156R108', '70450Y103', '149123101', '25746U109', '345370860', '03027X100',
            '369550108', '517834107', '61166W101', '693475105']


def main():
    nyse = mcal.get_calendar('NYSE')

    trade_date_range = pd.bdate_range(
        end=dt.date.fromisoformat("2017-01-10") - BusinessDay(n=1),
        periods=10,
        freq="C",
        holidays=list(nyse.holidays().holidays),
    )
    trade_date_range.name = "pricing_date"

    pricing_index = pd.MultiIndex.from_product([trade_date_range, ENTITIES], names=["pricing_date", "entity"])

    df = pd.DataFrame(index=pricing_index)

    print(df.loc['2017-01-09'].index.get_level_values("entity"))


if __name__ == '__main__':
    ray.init()
    main()
```


Discussion:

Resolving patch:
diff --git a/modin/pandas/indexing.py b/modin/pandas/indexing.py
--- a/modin/pandas/indexing.py
+++ b/modin/pandas/indexing.py
@@ -514,6 +514,8 @@ def __getitem__(self, key):
         --------
         pandas.DataFrame.loc
         """
+        if self.df.empty:
+            return self.df._default_to_pandas(lambda df: df.loc[key])
         row_loc, col_loc, ndim = self._parse_row_and_column_locators(key)
         self.row_scalar = is_scalar(row_loc)
         self.col_scalar = is_scalar(col_loc)
@@ -740,6 +742,8 @@ def __getitem__(self, key):
         --------
         pandas.DataFrame.iloc
         """
+        if self.df.empty:
+            return self.df._default_to_pandas(lambda df: df.iloc[key])
         row_loc, col_loc, ndim = self._parse_row_and_column_locators(key)
         self.row_scalar = is_scalar(row_loc)
         self.col_scalar = is_scalar(col_loc)


Test patch:
diff --git a/modin/pandas/test/dataframe/test_indexing.py b/modin/pandas/test/dataframe/test_indexing.py
--- a/modin/pandas/test/dataframe/test_indexing.py
+++ b/modin/pandas/test/dataframe/test_indexing.py
@@ -433,6 +433,16 @@ def test_loc_multi_index():
     df_equals(modin_df.loc[modin_df.index[:7]], pandas_df.loc[pandas_df.index[:7]])
 
 
+def test_loc_empty():
+    pandas_df = pandas.DataFrame(index=range(5))
+    modin_df = pd.DataFrame(index=range(5))
+
+    df_equals(pandas_df.loc[1], modin_df.loc[1])
+    pandas_df.loc[1] = 3
+    modin_df.loc[1] = 3
+    df_equals(pandas_df, modin_df)
+
+
 @pytest.mark.parametrize("index", [["row1", "row2", "row3"]])
 @pytest.mark.parametrize("columns", [["col1", "col2"]])
 def test_loc_assignment(index, columns):
@@ -541,6 +551,16 @@ def test_iloc_nested_assignment(data):
     df_equals(modin_df, pandas_df)
 
 
+def test_iloc_empty():
+    pandas_df = pandas.DataFrame(index=range(5))
+    modin_df = pd.DataFrame(index=range(5))
+
+    df_equals(pandas_df.iloc[1], modin_df.iloc[1])
+    pandas_df.iloc[1] = 3
+    modin_df.iloc[1] = 3
+    df_equals(pandas_df, modin_df)
+
+
 def test_loc_series():
     md_df, pd_df = create_test_dfs({"a": [1, 2], "b": [3, 4]})