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] Changing values at an index in list column is resulting in errors #11239

Closed
galipremsagar opened this issue Jul 11, 2022 · 2 comments
Closed
Assignees
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@galipremsagar
Copy link
Contributor

Describe the bug
When we try to modify values in list column using the user-facing __setitem__, there seems to be some failures.

Steps/Code to reproduce bug

In [1]: import cudf

In [2]: s = cudf.Series([[1, 2], [1], [2]])

In [3]: s
Out[3]: 
0    [1, 2]
1       [1]
2       [2]
dtype: list

In [4]: s[slice(0, 1, None)] = [3]
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 s[slice(0, 1, None)] = [3]

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/contextlib.py:79, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
     76 @wraps(func)
     77 def inner(*args, **kwds):
     78     with self._recreate_cm():
---> 79         return func(*args, **kwds)

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/series.py:1095, in Series.__setitem__(self, key, value)
   1092 @_cudf_nvtx_annotate
   1093 def __setitem__(self, key, value):
   1094     if isinstance(key, slice):
-> 1095         self.iloc[key] = value
   1096     else:
   1097         self.loc[key] = value

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/contextlib.py:79, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
     76 @wraps(func)
     77 def inner(*args, **kwds):
     78     with self._recreate_cm():
---> 79         return func(*args, **kwds)

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/series.py:147, in _SeriesIlocIndexer.__setitem__(self, key, value)
    142         value = value.astype(to_dtype)
    143         self._frame._column._mimic_inplace(
    144             self._frame._column.astype(to_dtype), inplace=True
    145         )
--> 147 self._frame._column[key] = value

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/column/lists.py:99, in ListColumn.__setitem__(self, key, value)
     97 else:
     98     raise ValueError(f"Can not set {value} into ListColumn")
---> 99 super().__setitem__(key, value)

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/column/column.py:494, in ColumnBase.__setitem__(self, key, value)
    492 out: Optional[ColumnBase]  # If None, no need to perform mimic inplace.
    493 if isinstance(key, slice):
--> 494     out = self._scatter_by_slice(key, value_normalized)
    495 else:
    496     key = as_column(key)

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/column/column.py:526, in ColumnBase._scatter_by_slice(self, key, value)
    524 if step == 1:
    525     if isinstance(value, cudf.core.scalar.Scalar):
--> 526         return self._fill(value, start, stop, inplace=True)
    527     else:
    528         return libcudf.copying.copy_range(
    529             value, self, 0, num_keys, start, stop, False
    530         )

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/column/column.py:340, in ColumnBase._fill(self, fill_value, begin, end, inplace)
    337     mask = create_null_mask(self.size, state=MaskState.ALL_VALID)
    338     self.set_base_mask(mask)
--> 340 libcudf.filling.fill_in_place(self, begin, end, slr.device_value)
    342 return self

File filling.pyx:31, in cudf._lib.filling.fill_in_place()

RuntimeError: cuDF failure at: /nvme/0/pgali/cudf/cpp/src/filling/fill.cu:214: In-place fill does not support variable-sized types.

In [5]: ps = s.to_pandas()

In [8]: ps[slice(0, 1, None)] = [[3]]

In [9]: ps
Out[9]: 
0    [3]
1    [1]
2    [2]
dtype: object

In [10]: s[slice(0, 1, None)] = [[3]]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [10], in <cell line: 1>()
----> 1 s[slice(0, 1, None)] = [[3]]

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/contextlib.py:79, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
     76 @wraps(func)
     77 def inner(*args, **kwds):
     78     with self._recreate_cm():
---> 79         return func(*args, **kwds)

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/series.py:1095, in Series.__setitem__(self, key, value)
   1092 @_cudf_nvtx_annotate
   1093 def __setitem__(self, key, value):
   1094     if isinstance(key, slice):
-> 1095         self.iloc[key] = value
   1096     else:
   1097         self.loc[key] = value

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/contextlib.py:79, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
     76 @wraps(func)
     77 def inner(*args, **kwds):
     78     with self._recreate_cm():
---> 79         return func(*args, **kwds)

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/series.py:147, in _SeriesIlocIndexer.__setitem__(self, key, value)
    142         value = value.astype(to_dtype)
    143         self._frame._column._mimic_inplace(
    144             self._frame._column.astype(to_dtype), inplace=True
    145         )
--> 147 self._frame._column[key] = value

File /nvme/0/pgali/envs/cudfdev/lib/python3.9/site-packages/cudf/core/column/lists.py:94, in ListColumn.__setitem__(self, key, value)
     92 if isinstance(value, cudf.Scalar):
     93     if value.dtype != self.dtype:
---> 94         raise TypeError("list nesting level mismatch")
     95 elif value is NA:
     96     value = cudf.Scalar(value, dtype=self.dtype)

TypeError: list nesting level mismatch

In [11]: 

Expected behavior
Match pandas behavior in this case.

Environment overview (please complete the following information)

  • Environment location: [Bare-metal]
  • Method of cuDF install: [from source]
@galipremsagar galipremsagar added bug Something isn't working Python Affects Python cuDF API. labels Jul 11, 2022
@galipremsagar galipremsagar self-assigned this Jul 11, 2022
@github-actions
Copy link

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

@galipremsagar
Copy link
Contributor Author

Duplicate of #11721

@galipremsagar galipremsagar marked this as a duplicate of #11721 Sep 23, 2022
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

No branches or pull requests

1 participant