Repository: modin-project/modin

Issue:
Assigning Series to an empty DataFrame produces an exception
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**:

Ubuntu 19.10

- **Modin version** (`modin.__version__`):

0.7.2+69.g91c768a

- **Python version**:

Python 3.7.5

- **Code we can use to reproduce**:

```python
import numpy as np
#import pandas as pd
import modin.pandas as pd

df = pd.DataFrame()
print(df)

df['id'] = pd.Series([1, 2])
print(df)
```

<!--
You can obtain the Modin version with

python -c "import modin; print(modin.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->

On modin the above code produces an exception:
```
Traceback (most recent call last):
  File "empty_df_test2.py", line 8, in <module>
    df['id'] = pd.Series([1, 2])
  File "/localdisk/gashiman/modin/modin/pandas/dataframe.py", line 2069, in __setitem__
    self._query_compiler.concat(1, value._query_compiler), inplace=True
  File "/localdisk/gashiman/modin/modin/backends/pandas/query_compiler.py", line 155, in concat
    new_modin_frame = self._modin_frame._concat(axis, other_modin_frame, join, sort)
  File "/localdisk/gashiman/modin/modin/engines/base/frame/data.py", line 1159, in _concat
    new_partitions = self._frame_mgr_cls.concat(axis, left_parts, right_parts)
  File "/localdisk/gashiman/modin/modin/engines/base/frame/partition_manager.py", line 303, in concat
    return np.concatenate([left_parts] + right_parts, axis=axis)
  File "<__array_function__ internals>", line 6, in concatenate
numpy.AxisError: axis 1 is out of bounds for array of dimension 1
```

### 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. -->

Assigning Series to an empty DataFrame produces an exception
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**:

Ubuntu 19.10

- **Modin version** (`modin.__version__`):

0.7.2+69.g91c768a

- **Python version**:

Python 3.7.5

- **Code we can use to reproduce**:

```python
import numpy as np
#import pandas as pd
import modin.pandas as pd

df = pd.DataFrame()
print(df)

df['id'] = pd.Series([1, 2])
print(df)
```

<!--
You can obtain the Modin version with

python -c "import modin; print(modin.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->

On modin the above code produces an exception:
```
Traceback (most recent call last):
  File "empty_df_test2.py", line 8, in <module>
    df['id'] = pd.Series([1, 2])
  File "/localdisk/gashiman/modin/modin/pandas/dataframe.py", line 2069, in __setitem__
    self._query_compiler.concat(1, value._query_compiler), inplace=True
  File "/localdisk/gashiman/modin/modin/backends/pandas/query_compiler.py", line 155, in concat
    new_modin_frame = self._modin_frame._concat(axis, other_modin_frame, join, sort)
  File "/localdisk/gashiman/modin/modin/engines/base/frame/data.py", line 1159, in _concat
    new_partitions = self._frame_mgr_cls.concat(axis, left_parts, right_parts)
  File "/localdisk/gashiman/modin/modin/engines/base/frame/partition_manager.py", line 303, in concat
    return np.concatenate([left_parts] + right_parts, axis=axis)
  File "<__array_function__ internals>", line 6, in concatenate
numpy.AxisError: axis 1 is out of bounds for array of dimension 1
```

### 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. -->



Discussion:

Resolving patch:
diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py
--- a/modin/pandas/dataframe.py
+++ b/modin/pandas/dataframe.py
@@ -2065,9 +2065,13 @@ def setitem_without_string_columns(df):
                 value = list(value)
         if key not in self.columns:
             if isinstance(value, Series):
-                self._create_or_update_from_compiler(
-                    self._query_compiler.concat(1, value._query_compiler), inplace=True
-                )
+                if len(self.columns) == 0:
+                    self._query_compiler = value._query_compiler.copy()
+                else:
+                    self._create_or_update_from_compiler(
+                        self._query_compiler.concat(1, value._query_compiler),
+                        inplace=True,
+                    )
                 # Now that the data is appended, we need to update the column name for
                 # that column to `key`, otherwise the name could be incorrect. Drop the
                 # last column name from the list (the appended value's name and append


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
@@ -708,6 +708,12 @@ def test_empty_df(self):
         pd_df["a"] = list("ABCDEF")
         df_equals(df, pd_df)
 
+        df = pd.DataFrame()
+        pd_df = pandas.DataFrame()
+        df["a"] = pd.Series([1, 2, 3, 4, 5])
+        pd_df["a"] = pandas.Series([1, 2, 3, 4, 5])
+        df_equals(df, pd_df)
+
     @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
     def test_abs(self, request, data):
         modin_df = pd.DataFrame(data)