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

Fix unbounded sequence issue in DataFrame constructor #13811

Merged
merged 4 commits into from
Aug 3, 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
6 changes: 6 additions & 0 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ def _init_from_list_like(self, data, index=None, columns=None):
data = DataFrame.from_pandas(pd.DataFrame(data))
self._data = data._data
else:
if any(
not isinstance(col, (abc.Iterable, abc.Sequence))
for col in data
):
raise TypeError("Inputs should be an iterable or sequence.")
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved

data = list(itertools.zip_longest(*data))

if columns is not None and len(data) == 0:
Expand Down
12 changes: 12 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10243,3 +10243,15 @@ def test_dataframe_init_columns_named_index():
pdf = pd.DataFrame(data, columns=columns)

assert_eq(gdf, pdf)


def test_dataframe_constructor_unbounded_sequence():
class A:
def __getitem__(self, key):
return 1

with pytest.raises(TypeError):
cudf.DataFrame([A()])

with pytest.raises(TypeError):
cudf.DataFrame({"a": A()})