Repository: modin-project/modin

Issue:
Assigning numpy.ndarray to a column produces an empty DataFrame
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**:

Ubuntu 19.10

- **Modin version** (`modin.__version__`):

0.7.1+3.ga8ff01a

- **Python version**:

Python 3.7.5

- **Code we can use to reproduce**:

```python
import numpy as np
#import pandas as pd
import ray
ray.init(huge_pages=False, plasma_directory="/localdisk/gashiman/plasma", memory=1024*1024*1024*200, object_store_memory=1024*1024*1024*200)
import modin.pandas as pd

df = pd.DataFrame(columns=['id', 'max_speed', 'health'])
print(df)

a = np.array(['one', 'two'])
print(type(a))
df['id'] = a
print(df)
```
<!--
You can obtain the Modin version with

python -c "import modin; print(modin.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->

There is a difference between Pandas and Modin behavior. After assignment in Pandas DataFrame has N row where N is the length of assigned array. In Modin assignment produces a DataFrame that is still empty.

### Source code / logs
<!-- Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem. -->

So in Pandas I am getting this output

```
Empty DataFrame
Columns: [id, max_speed, health]
Index: []
<class 'numpy.ndarray'>
    id max_speed health
0  one       NaN    NaN
1  two       NaN    NaN
```
while on Modin I get this
```
2020-02-28 14:22:55,644 INFO resource_spec.py:216 -- Starting Ray with 200.0 GiB memory available for workers and up to 200.0 GiB for objects. You can adjust these settings with ray.init(memory=<bytes>, object_store_memory=<bytes>).
2020-02-28 14:22:55,937 WARNING services.py:1365 -- WARNING: object_store_memory is not verified when plasma_directory is set.
UserWarning: Distributing <class 'NoneType'> object. This may take some time.
Empty DataFrame
Columns: [id, max_speed, health]
Index: []
<class 'numpy.ndarray'>
UserWarning: Distributing <class 'dict'> object. This may take some time.
Empty DataFrame
Columns: [id, max_speed, health]
Index: []
```


Discussion:
Thanks @gshimansky, this is a problem. I think it comes from how we handle empty dataframes, but I'll need to dig further to get a clear picture.
This only happens if I use numpy.ndarray in assignment. If I use a list it works exactly like Pandas does.

Resolving patch:
diff --git a/modin/pandas/base.py b/modin/pandas/base.py
--- a/modin/pandas/base.py
+++ b/modin/pandas/base.py
@@ -3386,17 +3386,16 @@ def __getattribute__(self, item):
         default_behaviors = [
             "__init__",
             "__class__",
-            "index",
             "_get_index",
             "_set_index",
             "empty",
             "index",
             "columns",
             "name",
-            "_get_name",
-            "_set_name",
             "dtypes",
             "dtype",
+            "_get_name",
+            "_set_name",
             "_default_to_pandas",
             "_query_compiler",
             "_to_pandas",
diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py
--- a/modin/pandas/dataframe.py
+++ b/modin/pandas/dataframe.py
@@ -1974,7 +1974,9 @@ def setitem_without_string_columns(df):
                 assert (
                     len(value.shape) < 3
                 ), "Shape of new values must be compatible with manager shape"
-                value = value.T.reshape(-1)[: len(self)]
+                value = value.T.reshape(-1)
+                if len(self) > 0:
+                    value = value[: len(self)]
             if not isinstance(value, Series):
                 value = list(value)
         if key not in self.columns:


Test patch:
diff --git a/modin/pandas/test/test_dataframe.py b/modin/pandas/test/test_dataframe.py
--- a/modin/pandas/test/test_dataframe.py
+++ b/modin/pandas/test/test_dataframe.py
@@ -5066,6 +5066,16 @@ def test___setitem__(self, data):
 
         df_equals(modin_df, pandas_df)
 
+    def test_setitem_on_empty_df(self):
+        columns = ["id", "max_speed", "health"]
+        modin_df = pd.DataFrame(columns=columns)
+        pandas_df = pandas.DataFrame(columns=columns)
+        a = np.array(["one", "two"])
+
+        modin_df["id"] = a
+        pandas_df["id"] = a
+        df_equals(modin_df, pandas_df)
+
     @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
     def test___len__(self, data):
         modin_df = pd.DataFrame(data)