Skip to content

Assigning a Series to an empty DataFrame produces exception #1490

@gshimansky

Description

@gshimansky

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):

Ubuntu 19.10

  • Modin version (modin.__version__):

0.7.3+46.g4286305

  • Python version:

Python 3.7.5

  • Code we can use to reproduce:
import modin.pandas as pd

df = pd.DataFrame()
se = pd.Series([11, 22, 33])
df[0] = se
print(df)

Describe the problem

This code generates exception

Traceback (most recent call last):
  File "/nfs/site/home/gashiman/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 3054, in _ensure_valid_index
    value = Series(value)
  File "/nfs/site/home/gashiman/.local/lib/python3.7/site-packages/pandas/core/series.py", line 256, in __init__
    data, index = self._init_dict(data, index, dtype)
  File "/nfs/site/home/gashiman/.local/lib/python3.7/site-packages/pandas/core/series.py", line 334, in _init_dict
    if data:
  File "/localdisk/gashiman/modin/modin/pandas/base.py", line 3343, in __nonzero__
    self.__class__.__name__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_setitem.py", line 5, in <module>
    df[0] = se
  File "/localdisk/gashiman/modin/modin/pandas/dataframe.py", line 2072, in __setitem__
    self._default_to_pandas(setitem_without_string_columns)._query_compiler
  File "/localdisk/gashiman/modin/modin/pandas/base.py", line 245, in _default_to_pandas
    result = op(pandas_obj, *args, **kwargs)
  File "/localdisk/gashiman/modin/modin/pandas/dataframe.py", line 2068, in setitem_without_string_columns
    df[key] = value
  File "/nfs/site/home/gashiman/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 2938, in __setitem__
    self._set_item(key, value)
  File "/nfs/site/home/gashiman/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 2999, in _set_item
    self._ensure_valid_index(value)
  File "/nfs/site/home/gashiman/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 3057, in _ensure_valid_index
    "Cannot set a frame with no defined index "
ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series

Source code / logs

Metadata

Metadata

Assignees

Labels

bug 🦗Something isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions