diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index 2f7cc4ba176..b4f3f533d44 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -5,6 +5,7 @@ import builtins import pickle import warnings +from collections import abc from functools import cached_property from itertools import chain from types import SimpleNamespace @@ -2384,12 +2385,16 @@ def as_column( return cudf.core.column.ListColumn.from_sequences( arbitrary ) - else: + elif isinstance(arbitrary, abc.Iterable) or isinstance( + arbitrary, abc.Sequence + ): data = as_column( _construct_array(arbitrary, dtype), dtype=dtype, nan_as_null=nan_as_null, ) + else: + raise e return data diff --git a/python/cudf/cudf/tests/test_series.py b/python/cudf/cudf/tests/test_series.py index 8be1f431ab3..83d22bbca2d 100644 --- a/python/cudf/cudf/tests/test_series.py +++ b/python/cudf/cudf/tests/test_series.py @@ -2204,3 +2204,12 @@ def test_series_contains(data, index): assert_eq(10 in ps, 10 in gs) assert_eq(True in ps, True in gs) assert_eq(False in ps, False in gs) + + +def test_series_constructor_unbounded_sequence(): + class A: + def __getitem__(self, key): + return 1 + + with pytest.raises(TypeError): + cudf.Series(A())