Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict iterables of DataFrame's as input to DataFrame constructor #14118

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,13 @@ def _init_from_list_like(self, data, index=None, columns=None):
elif len(data) > 0 and isinstance(data[0], pd._libs.interval.Interval):
data = DataFrame.from_pandas(pd.DataFrame(data))
self._data = data._data
elif any(
not isinstance(col, (abc.Iterable, abc.Sequence)) for col in data
):
raise TypeError("Inputs should be an iterable or sequence.")
elif len(data) > 0 and not can_convert_to_column(data[0]):
raise ValueError("Must pass 2-d input.")
else:
if any(
not isinstance(col, (abc.Iterable, abc.Sequence))
for col in data
):
raise TypeError("Inputs should be an iterable or sequence.")
if (
len(data) > 0
and columns is None
Expand Down
6 changes: 6 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10260,6 +10260,12 @@ def __getitem__(self, key):
cudf.DataFrame({"a": A()})


def test_dataframe_constructor_dataframe_list():
df = cudf.DataFrame(range(2))
with pytest.raises(ValueError):
cudf.DataFrame([df])


def test_dataframe_constructor_from_namedtuple():
Point1 = namedtuple("Point1", ["a", "b", "c"])
Point2 = namedtuple("Point1", ["x", "y"])
Expand Down
Loading