Skip to content

Commit

Permalink
Make Series(dtype=object) raise in mode.pandas_compat with non string…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
mroeschke authored Jan 24, 2025
1 parent 00dca76 commit 3d5cafc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ def as_column(
}:
if isinstance(dtype, (cudf.CategoricalDtype, cudf.IntervalDtype)):
dtype = dtype.to_pandas()
elif dtype == object:
elif dtype == object and not cudf.get_option("mode.pandas_compatible"):
# Unlike pandas, interpret object as "str" instead of "python object"
dtype = "str"
ser = pd.Series(arbitrary, dtype=dtype)
Expand Down
6 changes: 6 additions & 0 deletions python/cudf/cudf/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,12 @@ def test_roundtrip_series_plc_column(ps):
assert_eq(expect, actual)


def test_non_strings_dtype_object_pandas_compat_raises():
with cudf.option_context("mode.pandas_compatible", True):
with pytest.raises(TypeError):
cudf.Series([1], dtype=object)


def test_series_dataframe_count_float():
gs = cudf.Series([1, 2, 3, None, np.nan, 10], nan_as_null=False)
ps = cudf.Series([1, 2, 3, None, np.nan, 10])
Expand Down

0 comments on commit 3d5cafc

Please sign in to comment.