Skip to content

Commit 3d5cafc

Browse files
authored
Make Series(dtype=object) raise in mode.pandas_compat with non string data (#17804)
closes #17752 Authors: - Matthew Roeschke (https://github.com/mroeschke) - GALI PREM SAGAR (https://github.com/galipremsagar) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) URL: #17804
1 parent 00dca76 commit 3d5cafc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

python/cudf/cudf/core/column/column.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ def as_column(
23942394
}:
23952395
if isinstance(dtype, (cudf.CategoricalDtype, cudf.IntervalDtype)):
23962396
dtype = dtype.to_pandas()
2397-
elif dtype == object:
2397+
elif dtype == object and not cudf.get_option("mode.pandas_compatible"):
23982398
# Unlike pandas, interpret object as "str" instead of "python object"
23992399
dtype = "str"
24002400
ser = pd.Series(arbitrary, dtype=dtype)

python/cudf/cudf/tests/test_series.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,6 +3021,12 @@ def test_roundtrip_series_plc_column(ps):
30213021
assert_eq(expect, actual)
30223022

30233023

3024+
def test_non_strings_dtype_object_pandas_compat_raises():
3025+
with cudf.option_context("mode.pandas_compatible", True):
3026+
with pytest.raises(TypeError):
3027+
cudf.Series([1], dtype=object)
3028+
3029+
30243030
def test_series_dataframe_count_float():
30253031
gs = cudf.Series([1, 2, 3, None, np.nan, 10], nan_as_null=False)
30263032
ps = cudf.Series([1, 2, 3, None, np.nan, 10])

0 commit comments

Comments
 (0)