Skip to content
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

[BUG] Series UDFs documentation bug #9084

Closed
sarahyurick opened this issue Aug 20, 2021 · 5 comments · Fixed by #9104
Closed

[BUG] Series UDFs documentation bug #9084

sarahyurick opened this issue Aug 20, 2021 · 5 comments · Fixed by #9104
Assignees
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@sarahyurick
Copy link
Contributor

Hi, I was going through the Overview of User Defined Functions with cuDF documentation and tried out the first example, but got this error:

import numpy as np

import cudf
from cudf.datasets import randomdata

df = randomdata(nrows=10, dtypes={'a':float, 'b':bool, 'c':str}, seed=12)
# df.head()

def udf(x):
    if x > 0:
        return x + 5
    else:
        return x - 5

df['a'].applymap(udf)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_36751/1762304450.py in <module>
----> 1 df['a'].applymap(udf)

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/series.py in applymap(self, udf, out_dtype)
   3904         if not callable(udf):
   3905             raise ValueError("Input UDF must be a callable object.")
-> 3906         return self._from_data({self.name: self._unaryop(udf)}, self._index)
   3907 
   3908     #

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/frame.py in _unaryop(self, op)
   3422     def _unaryop(self, op):
   3423         data_columns = (col.unary_operator(op) for col in self._columns)
-> 3424         return self.__class__._from_data(
   3425             zip(self._column_names, data_columns), self._index
   3426         )

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/series.py in _from_data(cls, data, index, name)
    278         Construct the Series from a ColumnAccessor
    279         """
--> 280         out: Series = super()._from_data(data, index, name)
    281         if index is None:
    282             out._index = RangeIndex(out._data.nrows)

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/frame.py in _from_data(cls, data, index, name)
   4449     ):
   4450 
-> 4451         out = super()._from_data(data, index)
   4452         if name is not None:
   4453             out.name = name

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/frame.py in _from_data(cls, data, index)
     71     ):
     72         obj = cls.__new__(cls)
---> 73         libcudf.table.Table.__init__(obj, data, index)
     74         return obj
     75 

cudf/_lib/table.pyx in cudf._lib.table.Table.__init__()

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/column_accessor.py in __init__(self, data, multiindex, level_names)
    119             self._data = {}
    120             if data:
--> 121                 data = dict(data)
    122                 # Faster than next(iter(data.values()))
    123                 column_length = len(data[next(iter(data))])

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/frame.py in <genexpr>(.0)
   3421 
   3422     def _unaryop(self, op):
-> 3423         data_columns = (col.unary_operator(op) for col in self._columns)
   3424         return self.__class__._from_data(
   3425             zip(self._column_names, data_columns), self._index

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/column/numerical.py in unary_operator(self, unaryop)
    120 
    121     def unary_operator(self, unaryop: str) -> ColumnBase:
--> 122         return _numeric_column_unaryop(self, op=unaryop)
    123 
    124     def binary_operator(

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/core/column/numerical.py in _numeric_column_unaryop(operand, op)
    592 def _numeric_column_unaryop(operand: ColumnBase, op: str) -> ColumnBase:
    593     if callable(op):
--> 594         return libcudf.transform.transform(operand, op)
    595 
    596     op = libcudf.unary.UnaryOp[op.upper()]

cudf/_lib/transform.pyx in cudf._lib.transform.transform()

~/miniconda3/envs/cudf_dev/lib/python3.8/site-packages/cudf/utils/cudautils.py in compile_udf(udf, type_signature)
    261         udf, type_signature, device=True
    262     )
--> 263     if not isinstance(return_type, cudf.core.udf.typing.MaskedType):
    264         output_type = numpy_support.as_dtype(return_type).type
    265     else:

AttributeError: module 'cudf.core' has no attribute 'udf'
@sarahyurick sarahyurick added bug Something isn't working Needs Triage Need team to review and classify labels Aug 20, 2021
@beckernick
Copy link
Member

beckernick commented Aug 20, 2021

This may have shaken out during the ongoing python refactor. We still have a cudf.core.udf namespace, but the __init__.py in cudf.core is now empty

https://github.com/rapidsai/cudf/blob/58692648043eb07d92e8462224c3eee9d8febb3d/python/cudf/cudf/core/__init__.py

@beckernick beckernick added Python Affects Python cuDF API. and removed Needs Triage Need team to review and classify labels Aug 20, 2021
@beckernick beckernick added this to the CuDF Python Refactoring milestone Aug 20, 2021
@beckernick
Copy link
Member

Looks like it was removed in #8949

@efajardo-nv
Copy link
Contributor

hi @beckernick. fyi we just started getting the same error in the clx 21.10 nightly builds where we use udf's.

@shwina shwina self-assigned this Aug 24, 2021
@shwina
Copy link
Contributor

shwina commented Aug 24, 2021

fix coming up

@shwina shwina mentioned this issue Aug 24, 2021
@efajardo-nv
Copy link
Contributor

thanks ashwin!

rapids-bot bot pushed a commit that referenced this issue Aug 25, 2021
Closes #9084

Authors:
  - Ashwin Srinath (https://github.com/shwina)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #9104
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants