Skip to content

Commit

Permalink
Address comments, delete test
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt711 committed May 23, 2024
1 parent 6e5fcbf commit 8ac0997
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 13 deletions.
10 changes: 5 additions & 5 deletions python/cudf/cudf/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ def _integer_and_none_validator(val):
False,
textwrap.dedent(
"""
If set to `False`, retains `cudf` specific behavior.
If set to `True`, enables pandas debugging mode,
which will raise a warning if the results from cudf
and pandas differ.
\tValid values are True or False. Default is False.
If set to `True`, enables cudf.pandas debugging mode.
When enabled, cudf code paths in cudf.pandas will
also run with pandas and raise a warning if the
results from cudf and pandas differ.
If set to `False`, cudf.pandas debugging is disabled.
"""
),
_make_contains_validator([False, True]),
Expand Down
131 changes: 127 additions & 4 deletions python/cudf/cudf/pandas/fast_slow_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import operator
import pickle
import types
import warnings
from collections.abc import Iterator
from enum import IntEnum
from typing import (
Expand All @@ -23,9 +24,13 @@
Type,
)

from cudf.testing._utils import assert_eq

from ..options import get_option
from .annotation import nvtx

# from cudf.pandas._wrappers.pandas import Timedelta, Timestamp, DataFrame, Series, Index, RangeIndex, SparseDtype, SparseArray, CategoricalIndex, Categorical, CategoricalDtype, DatetimeIndex, DatetimeArray, DatetimeTZDtype, TimedeltaIndex, NumpyExtensionArray, PandasArray, TimedeltaArray, PeriodIndex, PeriodArray, PeriodDtype, Period, MultiIndex, Grouper, StringArray, StringDtype, BooleanArray, BooleanDtype, IntegerArray, Int8Dtype, Int16Dtype, Int32Dtype, Int64Dtype, UInt8Dtype, UInt16Dtype, UInt32Dtype, UInt64Dtype, IntervalIndex, IntervalArray, IntervalDtype, Interval, FloatingArray, Float32Dtype, Float64Dtype, FixedForwardWindowIndexer, VariableOffsetWindowIndexer, HDFStore, ExcelFile, ExcelWriter, Styler, USFederalHolidayCalendar, HolidayCalendarMetaClass, AbstractHolidayCalendar, Holiday, USThanksgivingDay, USColumbusDay, USLaborDay, USMemorialDay, USMartinLutherKingJr, USPresidentsDay, GoodFriday, EasterMonday, FY5253, BDay, BMonthBegin, BMonthEnd, BQuarterBegin, BQuarterEnd, BusinessDay, BusinessHour, BusinessMonthBegin, BusinessMonthEnd, BYearBegin, BYearEnd, CBMonthBegin, CBMonthEnd, CDay, CustomBusinessDay, CustomBusinessHour, CustomBusinessMonthBegin, CustomBusinessMonthEnd, DateOffset, BaseOffset, Day, Easter, FY5253Quarter, Hour, LastWeekOfMonth, Micro, Milli, Minute, MonthBegin, MonthEnd, Nano, QuarterBegin, QuarterEnd, Second, SemiMonthBegin, SemiMonthEnd, Tick, Week, WeekOfMonth, YearBegin, YearEnd, Flags, NamedAgg, ArrowExtensionArray


def call_operator(fn, args, kwargs):
return fn(*args, **kwargs)
Expand Down Expand Up @@ -902,15 +907,23 @@ def _fast_slow_function_call(func: Callable, /, *args, **kwargs) -> Any:

if get_option("mode.pandas_debugging"):
with nvtx.annotate(
"EXECUTE_SLOW",
"EXECUTE_SLOW_DEBUGGING",
color=_CUDF_PANDAS_NVTX_COLORS["EXECUTE_SLOW"],
domain="cudf_pandas",
):
slow_args, slow_kwargs = _slow_arg(args), _slow_arg(kwargs)
with disable_module_accelerator():
result_slow = func(*slow_args, **slow_kwargs)
print(result_slow)
# TODO: Compare result and result slow and return a warning
slow_result = func(*slow_args, **slow_kwargs)
print("FAST ", result, type(result))
print("SLOW ", slow_result, type(slow_result))
if type(result).__name__ in _CUDF_OBJ_FINAL_TYPES:
assert_eq(result, slow_result)
except AssertionError:
warnings.warn(
"The results from cudf and pandas were different. "
f"The types were {type(result)} and {type(slow_result)} for cudf and pandas, respectively."
)
return _maybe_wrap_result(result, func, *args, **kwargs), fast
except Exception:
with nvtx.annotate(
"EXECUTE_SLOW",
Expand Down Expand Up @@ -1156,6 +1169,116 @@ def _replace_closurevars(
)


_CUDF_OBJ_FINAL_TYPES: Set[str] = {
"Timedelta",
"Timestamp",
"DataFrame",
"Series",
"Index",
"RangeIndex",
"SparseDtype",
"SparseArray",
"CategoricalIndex",
"Categorical",
"CategoricalDtype",
"DatetimeIndex",
"DatetimeArray",
"DatetimeTZDtype",
"TimedeltaIndex",
"NumpyExtensionArray",
"PandasArray",
"TimedeltaArray",
"PeriodIndex",
"PeriodArray",
"PeriodDtype",
"Period",
"MultiIndex",
"Grouper",
"StringArray",
"StringDtype",
"BooleanArray",
"BooleanDtype",
"IntegerArray",
"Int8Dtype",
"Int16Dtype",
"Int32Dtype",
"Int64Dtype",
"UInt8Dtype",
"UInt16Dtype",
"UInt32Dtype",
"UInt64Dtype",
"IntervalIndex",
"IntervalArray",
"IntervalDtype",
"Interval",
"FloatingArray",
"Float32Dtype",
"Float64Dtype",
"FixedForwardWindowIndexer",
"VariableOffsetWindowIndexer",
"HDFStore",
"ExcelFile",
"ExcelWriter",
"Styler",
"USFederalHolidayCalendar",
"HolidayCalendarMetaClass",
"AbstractHolidayCalendar",
"Holiday",
"USThanksgivingDay",
"USColumbusDay",
"USLaborDay",
"USMemorialDay",
"USMartinLutherKingJr",
"USPresidentsDay",
"GoodFriday",
"EasterMonday",
"FY5253",
"BDay",
"BMonthBegin",
"BMonthEnd",
"BQuarterBegin",
"BQuarterEnd",
"BusinessDay",
"BusinessHour",
"BusinessMonthBegin",
"BusinessMonthEnd",
"BYearBegin",
"BYearEnd",
"CBMonthBegin",
"CBMonthEnd",
"CDay",
"CustomBusinessDay",
"CustomBusinessHour",
"CustomBusinessMonthBegin",
"CustomBusinessMonthEnd",
"DateOffset",
"BaseOffset",
"Day",
"Easter",
"FY5253Quarter",
"Hour",
"LastWeekOfMonth",
"Micro",
"Milli",
"Minute",
"MonthBegin",
"MonthEnd",
"Nano",
"QuarterBegin",
"QuarterEnd",
"Second",
"SemiMonthBegin",
"SemiMonthEnd",
"Tick",
"Week",
"WeekOfMonth",
"YearBegin",
"YearEnd",
"Flags",
"NamedAgg",
"ArrowExtensionArray",
}

_SPECIAL_METHODS: Set[str] = {
"__abs__",
"__add__",
Expand Down
4 changes: 0 additions & 4 deletions python/cudf/cudf_pandas_tests/test_fast_slow_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,3 @@ def test_tuple_with_attrs_transform():
assert b == bprime and b is not bprime
assert c == cprime and c is not cprime
assert d == dprime and d is not dprime


def test_fast_slow_function_call():
assert True

0 comments on commit 8ac0997

Please sign in to comment.