From c72868e9f19fe496486773f69e5558f90f999216 Mon Sep 17 00:00:00 2001 From: brandon-b-miller <53796099+brandon-b-miller@users.noreply.github.com> Date: Wed, 13 Apr 2022 16:35:37 -0500 Subject: [PATCH] Remove implementation details from `apply` docstrings (#10651) Removes some unnecessary implementation detail from `apply` docstrings and updates them where necessary. Authors: - https://github.com/brandon-b-miller Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) - Ashwin Srinath (https://github.com/shwina) URL: https://github.com/rapidsai/cudf/pull/10651 --- python/cudf/cudf/core/dataframe.py | 25 +++++++++++++------------ python/cudf/cudf/core/series.py | 16 +++++++++++----- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 277fd5aae57..7c209086663 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -3564,12 +3564,13 @@ def apply( ): """ Apply a function along an axis of the DataFrame. - - Designed to mimic `pandas.DataFrame.apply`. Applies a user - defined function row wise over a dataframe, with true null - handling. Works with UDFs using `core.udf.pipeline.nulludf` - and returns a single series. Uses numba to jit compile the - function to PTX via LLVM. + ``apply`` relies on Numba to JIT compile ``func``. + Thus the allowed operations within ``func`` are limited + to the ones specified + [here](https://numba.pydata.org/numba-doc/latest/cuda/cudapysupported.html). + For more information, see the cuDF guide + to user defined functions found + [here](https://docs.rapids.ai/api/cudf/stable/user_guide/guide-to-udfs.html). Parameters ---------- @@ -3590,7 +3591,7 @@ def apply( Examples -------- - Simple function of a single variable which could be NA + Simple function of a single variable which could be NA: >>> def f(row): ... if row['a'] is cudf.NA: @@ -3606,7 +3607,7 @@ def apply( dtype: int64 Function of multiple variables will operate in - a null aware manner + a null aware manner: >>> def f(row): ... return row['a'] - row['b'] @@ -3622,7 +3623,7 @@ def apply( 3 dtype: int64 - Functions may conditionally return NA as in pandas + Functions may conditionally return NA as in pandas: >>> def f(row): ... if row['a'] + row['b'] > 3: @@ -3641,7 +3642,7 @@ def apply( dtype: int64 Mixed types are allowed, but will return the common - type, rather than object as in pandas + type, rather than object as in pandas: >>> def f(row): ... return row['a'] + row['b'] @@ -3658,7 +3659,7 @@ def apply( Functions may also return scalar values, however the result will be promoted to a safe type regardless of - the data + the data: >>> def f(row): ... if row['a'] > 3: @@ -3675,7 +3676,7 @@ def apply( 2 5.0 dtype: float64 - Ops against N columns are supported generally + Ops against N columns are supported generally: >>> def f(row): ... v, w, x, y, z = ( diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index 5bf52ed7520..6e15c03e6b4 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -2021,9 +2021,15 @@ def _return_sentinel_series(): def apply(self, func, convert_dtype=True, args=(), **kwargs): """ Apply a scalar function to the values of a Series. + Similar to ``pandas.Series.apply``. - Similar to `pandas.Series.apply. Applies a user - defined function elementwise over a series. + ``apply`` relies on Numba to JIT compile ``func``. + Thus the allowed operations within ``func`` are limited + to the ones specified + [here](https://numba.pydata.org/numba-doc/latest/cuda/cudapysupported.html). + For more information, see the cuDF guide to + user defined functions found + [here](https://docs.rapids.ai/api/cudf/stable/user_guide/guide-to-udfs.html). Parameters ---------- @@ -2061,7 +2067,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwargs): 2 4 dtype: int64 - Apply a basic function to a series with nulls + Apply a basic function to a series with nulls: >>> sr = cudf.Series([1,cudf.NA,3]) >>> def f(x): @@ -2073,7 +2079,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwargs): dtype: int64 Use a function that does something conditionally, - based on if the value is or is not null + based on if the value is or is not null: >>> sr = cudf.Series([1,cudf.NA,3]) >>> def f(x): @@ -2091,7 +2097,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwargs): as derived from the UDFs logic. Note that this means the common type will be returned even if such data is passed that would not result in any values of that - dtype. + dtype: >>> sr = cudf.Series([1,cudf.NA,3]) >>> def f(x):