-
Notifications
You must be signed in to change notification settings - Fork 917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup how args and kwargs are passed in _fast_slow_function_call
#16266
base: branch-25.02
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Matt711 Could you explain what the issue is your are seeing?
In |
It's still a little unclear how this bug would manifest. For example, this still raises In [1]: %load_ext cudf.pandas
In [2]: import pandas as pd
In [3]: pd.Timestamp(2020, 1, 1, year=2021)
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
File ~/mroeschke-cudf/python/cudf/cudf/pandas/fast_slow_proxy.py:896, in _fast_slow_function_call(func, *args, **kwargs)
891 with nvtx.annotate(
892 "EXECUTE_FAST",
893 color=_CUDF_PANDAS_NVTX_COLORS["EXECUTE_FAST"],
894 domain="cudf_pandas",
895 ):
--> 896 fast_args, fast_kwargs = _fast_arg(args), _fast_arg(kwargs)
897 result = func(*fast_args, **fast_kwargs)
File ~/mroeschke-cudf/python/cudf/cudf/pandas/fast_slow_proxy.py:1046, in _fast_arg(arg)
1045 seen: set[int] = set()
-> 1046 return _transform_arg(arg, "_fsproxy_fast", seen)
File ~/mroeschke-cudf/python/cudf/cudf/pandas/fast_slow_proxy.py:973, in _transform_arg(arg, attribute_name, seen)
971 if type(arg) is tuple:
972 # Must come first to avoid infinite recursion
--> 973 return tuple(_transform_arg(a, attribute_name, seen) for a in arg)
974 elif hasattr(arg, "__getnewargs_ex__"):
975 # Partial implementation of to reconstruct with
976 # transformed pieces
977 # This handles scipy._lib._bunch._make_tuple_bunch
File ~/mroeschke-cudf/python/cudf/cudf/pandas/fast_slow_proxy.py:973, in <genexpr>(.0)
971 if type(arg) is tuple:
972 # Must come first to avoid infinite recursion
--> 973 return tuple(_transform_arg(a, attribute_name, seen) for a in arg)
974 elif hasattr(arg, "__getnewargs_ex__"):
975 # Partial implementation of to reconstruct with
976 # transformed pieces
977 # This handles scipy._lib._bunch._make_tuple_bunch
File ~/mroeschke-cudf/python/cudf/cudf/pandas/fast_slow_proxy.py:958, in _transform_arg(arg, attribute_name, seen)
957 if typ is _Unusable:
--> 958 raise Exception("Cannot transform _Unusable")
959 return typ
Exception: Cannot transform _Unusable
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Cell In[3], line 1
----> 1 pd.Timestamp(2020, 1, 1, year=2021)
File ~/mroeschke-cudf/python/cudf/cudf/pandas/_wrappers/pandas.py:131, in Timestamp_Timedelta__new__(cls, *args, **kwargs)
124 def Timestamp_Timedelta__new__(cls, *args, **kwargs):
125 # Call fast/slow constructor
126 # This takes care of running __init__ as well, but must be paired
(...)
129 # Timestamp & Timedelta don't always return same types as self,
130 # hence this method is needed.
--> 131 self, _ = _fast_slow_function_call(
132 lambda cls, args, kwargs: cls(*args, **kwargs),
133 cls,
134 args,
135 kwargs,
136 )
137 return self
File ~/mroeschke-cudf/python/cudf/cudf/pandas/fast_slow_proxy.py:941, in _fast_slow_function_call(func, *args, **kwargs)
939 slow_args, slow_kwargs = _slow_arg(args), _slow_arg(kwargs)
940 with disable_module_accelerator():
--> 941 result = func(*slow_args, **slow_kwargs)
942 return _maybe_wrap_result(result, func, *args, **kwargs), fast
File ~/mroeschke-cudf/python/cudf/cudf/pandas/_wrappers/pandas.py:132, in Timestamp_Timedelta__new__.<locals>.<lambda>(cls, args, kwargs)
124 def Timestamp_Timedelta__new__(cls, *args, **kwargs):
125 # Call fast/slow constructor
126 # This takes care of running __init__ as well, but must be paired
(...)
129 # Timestamp & Timedelta don't always return same types as self,
130 # hence this method is needed.
131 self, _ = _fast_slow_function_call(
--> 132 lambda cls, args, kwargs: cls(*args, **kwargs),
133 cls,
134 args,
135 kwargs,
136 )
137 return self
File timestamps.pyx:1725, in pandas._libs.tslibs.timestamps.Timestamp.__new__()
TypeError: __new__() got multiple values for keyword argument 'year' |
Yeah I would expect that example to still raise. This PR just addresses the fact that |
@Matt711 Could you please add a couple of tests that are currently failing and pass with this fix? |
I don't think there's a good way to test this PR because all it does is change how we call
With the second option, we unpack the args and kwargs so that kwargs are not always empty (so this is more of a general python thing). I labeled this a bug but there's nothing really incorrect here in the sense of an incorrect result from My apologies for any confusion. |
If there's not strict bug here, IMO I would just treat this as a "cleanup" and just remove |
I agree with @mroeschke. No need to label this a bug, but let's simplify the API to reduce the possibility of error for devs in the future. |
ac473ae
to
48501be
Compare
_fast_slow_function_call
_fast_slow_function_call
_slow_arg(args), | ||
_slow_arg(kwargs), | ||
) | ||
slow_args = (_slow_arg(args),) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slow_args = (_slow_arg(args),) | |
slow_args = _slow_arg(args) |
@@ -874,7 +874,6 @@ def _fast_slow_function_call( | |||
func: Callable, | |||
/, | |||
*args, | |||
**kwargs, | |||
) -> Any: | |||
""" | |||
Call `func` with all `args` and `kwargs` converted to their |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this docstring to note that args
contains func
's args and kwargs?
Looks like this needs some conflict resolution, and there are some discussions to be addressed @Matt711. |
TODO: Check if this improvement PR is still relevant. |
Description
I think
kwargs
are being subsumed byargs
in_fast_slow_function_call
when they shouldn't.Checklist