Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
9 changes: 2 additions & 7 deletions python/cudf/cudf/core/accessors/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from cudf.core.accessors.lists import ListMethods
from cudf.core.column.column import ColumnBase, as_column, column_empty
from cudf.core.dtypes import ListDtype
from cudf.options import get_option
from cudf.utils.dtypes import (
CUDF_STRING_DTYPE,
can_convert_to_column,
Expand Down Expand Up @@ -4203,10 +4202,8 @@ def index(

if (result == -1).any():
raise ValueError("substring not found")
elif get_option("mode.pandas_compatible"):
return result.astype(np.dtype(np.int64))
else:
return result
return result.astype(np.dtype(np.int64))

def rindex(
self, sub: str, start: int = 0, end: int | None = None
Expand Down Expand Up @@ -4265,10 +4262,8 @@ def rindex(

if (result == -1).any():
raise ValueError("substring not found")
elif get_option("mode.pandas_compatible"):
return result.astype(np.dtype(np.int64))
else:
return result
return result.astype(np.dtype(np.int64))

def match(
self,
Expand Down
11 changes: 2 additions & 9 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,13 +1661,7 @@ def notnull(self) -> ColumnBase:
plc.unary.is_valid(self.plc_column), np.dtype(np.bool_)
)

if cudf.get_option("mode.pandas_compatible"):
return result

return ColumnBase.create(
result.plc_column,
get_dtype_of_same_kind(self.dtype, np.dtype(np.bool_)),
)
return result

@cached_property
def nan_count(self) -> int:
Expand Down Expand Up @@ -3027,8 +3021,7 @@ def as_column(
)
)
elif (
cudf.get_option("mode.pandas_compatible")
and isinstance(arbitrary.dtype, pd.CategoricalDtype)
isinstance(arbitrary.dtype, pd.CategoricalDtype)
and is_pandas_nullable_extension_dtype(
arbitrary.dtype.categories.dtype
)
Expand Down
5 changes: 1 addition & 4 deletions python/cudf/cudf/core/column/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import pylibcudf as plc

import cudf
from cudf.core.column.column import ColumnBase, _handle_nulls, as_column
from cudf.core.dtype.validators import is_dtype_obj_interval
from cudf.core.dtypes import IntervalDtype, _dtype_to_metadata
Expand Down Expand Up @@ -267,8 +266,6 @@ def element_indexing(
if isinstance(result, pa.Scalar):
py_element = maybe_nested_pa_scalar_to_py(result)
result = self.dtype._recursively_replace_fields(py_element) # type: ignore[union-attr]
if isinstance(result, dict) and cudf.get_option(
"mode.pandas_compatible"
):
if isinstance(result, dict):
return pd.Interval(**result, closed=self.dtype.closed) # type: ignore[union-attr]
return result
7 changes: 1 addition & 6 deletions python/cudf/cudf/core/column/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,7 @@ def notnull(self) -> ColumnBase:
# For floats, NaN should be considered null
result = result & self.notnan()

if cudf.get_option("mode.pandas_compatible"):
return result

return result._with_type_metadata(
get_dtype_of_same_kind(self.dtype, np.dtype(np.bool_))
)
return result

def element_indexing(self, index: int) -> ScalarLike | None:
result = super().element_indexing(index)
Expand Down
10 changes: 3 additions & 7 deletions python/cudf/cudf/core/column/temporal_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,7 @@ def element_indexing(self, index: int) -> ScalarLike:
if result is self._PANDAS_NA_VALUE:
return result
result = result.as_py()
if cudf.get_option("mode.pandas_compatible"):
return self._PD_SCALAR(result)
elif isinstance(result, self._PD_SCALAR):
return result.to_numpy()
return self.dtype.type(result).astype(self.dtype, copy=False)
return self._PD_SCALAR(result)

def to_pandas(
self,
Expand Down Expand Up @@ -310,11 +306,11 @@ def can_cast_safely(self, to_dtype: DtypeObj) -> bool:
to_res, _ = np.datetime_data(to_dtype)
max_val = self.max()
if isinstance(max_val, (pd.Timedelta, pd.Timestamp)):
max_val = max_val.to_numpy()
max_val = max_val.to_numpy().astype(self.dtype)
max_val = max_val.astype(self._UNDERLYING_DTYPE, copy=False)
min_val = self.min()
if isinstance(min_val, (pd.Timedelta, pd.Timestamp)):
min_val = min_val.to_numpy()
min_val = min_val.to_numpy().astype(self.dtype)
min_val = min_val.astype(self._UNDERLYING_DTYPE, copy=False)
# call-overload must be ignored because numpy stubs only accept literal strings
# for time units (e.g., "ns", "us") to allow compile-time validation,
Expand Down
14 changes: 6 additions & 8 deletions python/cudf/cudf/core/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,14 +1065,12 @@ def to_arrow(self) -> ArrowIntervalType:
)

def to_pandas(self) -> pd.IntervalDtype:
if cudf.get_option("mode.pandas_compatible"):
return pd.IntervalDtype(
subtype=self.subtype.numpy_dtype
if is_pandas_nullable_extension_dtype(self.subtype)
else self.subtype,
closed=self.closed,
)
return pd.IntervalDtype(subtype=self.subtype, closed=self.closed)
return pd.IntervalDtype(
subtype=self.subtype.numpy_dtype
if is_pandas_nullable_extension_dtype(self.subtype)
else self.subtype,
closed=self.closed,
)

def __eq__(self, other) -> bool:
if isinstance(other, str):
Expand Down
4 changes: 1 addition & 3 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,7 @@ def to_array(
elif to_dtype.kind in "ui":
to_dtype = np.dtype("float64")

if cudf.get_option(
"mode.pandas_compatible"
) and is_pandas_nullable_extension_dtype(to_dtype):
if is_pandas_nullable_extension_dtype(to_dtype):
to_dtype = getattr(to_dtype, "numpy_dtype", to_dtype)
if getattr(to_dtype, "kind", None) == "U":
to_dtype = np.dtype(object)
Expand Down
41 changes: 20 additions & 21 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,9 @@ def _scan(
if cast_to_int and result_col.dtype.kind in "uib":
# For reductions that accumulate a value (e.g. sum, not max)
# pandas returns an int64 dtype for all int or bool dtypes.
if cudf.get_option("mode.pandas_compatible"):
dtype = get_dtype_of_same_kind(
result_col.dtype, np.dtype(np.int64)
)
else:
dtype = np.dtype(np.int64)
dtype = get_dtype_of_same_kind(
result_col.dtype, np.dtype(np.int64)
)
Comment thread
galipremsagar marked this conversation as resolved.
Resolved
result_col = result_col.astype(dtype)
results.append(getattr(result_col, op)(inclusive=True))
return self._from_data_like_self(
Expand Down Expand Up @@ -7045,27 +7042,29 @@ def _append_new_row_inplace(col: ColumnBase, value: ScalarLike) -> None:
val_col = val_col.astype(col.dtype)
to_type = col.dtype
else:
if (
cudf.get_option("mode.pandas_compatible")
and is_pandas_nullable_extension_dtype(col.dtype)
and val_col.dtype.kind == "f"
):
# If the column is a pandas nullable extension type, we need to
# convert the nans to a nullable type as well.
val_col = val_col.nans_to_nulls()
if len(val_col) == val_col.null_count:
# If the column is all nulls, we can use the column dtype
# to avoid unnecessary casting.
val_col = val_col.astype(col.dtype)
to_type = find_common_type([val_col.dtype, col.dtype])
to_type = None
if is_pandas_nullable_extension_dtype(col.dtype):
if val_col.dtype.kind == "f":
# If the column is a pandas nullable extension type, we need to
# convert the nans to a nullable type as well.
val_col = val_col.nans_to_nulls()
if len(val_col) == val_col.null_count:
# If the column is all nulls, we can use the column dtype
# to avoid unnecessary casting.
val_col = val_col.astype(col.dtype)
if val_col.can_cast_safely(col.dtype):
to_type = col.dtype
if to_type is None:
to_type = find_common_type([val_col.dtype, col.dtype])

if (
cudf.get_option("mode.pandas_compatible")
and is_string_dtype(to_type)
and is_mixed_with_object_dtype(val_col, col)
):
raise MixedTypeError("Cannot append mixed types")
if cudf.get_option(
"mode.pandas_compatible"
if is_pandas_nullable_extension_dtype(
col.dtype
) and val_col.can_cast_safely(col.dtype):
to_type = col.dtype
val_col = val_col.astype(to_type)
Expand Down
6 changes: 2 additions & 4 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1918,10 +1918,8 @@ def any(
"The bool_only parameter is not supported for Series."
)
result = super().any(axis, skipna, **kwargs)
if (
cudf.get_option("mode.pandas_compatible")
and isinstance(result, bool)
and not isinstance(self.dtype, pd.ArrowDtype)
if isinstance(result, bool) and not isinstance(
self.dtype, pd.ArrowDtype
):
return np.bool_(result)
return result
Expand Down
2 changes: 0 additions & 2 deletions python/cudf/cudf/pandas/scripts/conftest-patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4256,7 +4256,6 @@ def set_copy_on_write_option():
"tests/indexes/multi/test_sorting.py::test_remove_unused_levels_large[datetime64[D]-str]",
"tests/indexes/multi/test_sorting.py::test_remove_unused_levels_large[int64-int64]",
"tests/indexes/multi/test_sorting.py::test_unsortedindex_doc_examples",
"tests/indexes/numeric/test_astype.py::TestAstype::test_astype_float64_to_uint64",
"tests/indexes/numeric/test_indexing.py::TestGetIndexer::test_get_indexer_invalid",
"tests/indexes/numeric/test_indexing.py::TestGetIndexer::test_get_indexer_nan",
"tests/indexes/numeric/test_indexing.py::TestGetIndexer::test_get_indexer_nearest_decreasing[backfill-expected1]",
Expand Down Expand Up @@ -4865,7 +4864,6 @@ def set_copy_on_write_option():
"tests/indexing/test_partial.py::TestEmptyFrameSetitemExpansion::test_partial_set_empty_frame3",
"tests/indexing/test_partial.py::TestEmptyFrameSetitemExpansion::test_partial_set_empty_frame5",
"tests/indexing/test_partial.py::TestPartialSetting::test_loc_with_list_of_strings_representing_datetimes[DataFrame-idx1-labels1-expected_idx1]",
"tests/indexing/test_partial.py::TestPartialSetting::test_partial_setting",
"tests/indexing/test_partial.py::TestPartialSetting::test_partial_setting_frame",
"tests/indexing/test_partial.py::TestPartialSetting::test_partial_setting_mixed_dtype",
"tests/indexing/test_scalar.py::TestMultiIndexScalar::test_multiindex_at_get_one_level",
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/tests/input_output/test_csv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2018-2025, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0

import codecs
Expand Down Expand Up @@ -1077,7 +1077,7 @@ def test_csv_reader_tabs():
np.testing.assert_allclose(floats, df["float_point"].to_numpy())
np.testing.assert_allclose(ints, df["integer"].to_numpy())
for row in range(4):
assert str(df["date"][row]) == dates[row]
assert str(df["date"][row].to_numpy()) == dates[row]


@pytest.mark.parametrize("segment_bytes", [10000, 19999, 30001, 36000])
Expand Down
Loading