NVIDIA / NVIDIA/cudf

[BUG] IndexError during assignment through loc[]

Open
#12,504 0 comments 0 reactions 0 assignees View on GitHub
0 - Backlog bug Python
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

**Describe the bug**
rewriting code with `import cudf as pd`

**Steps/Code to reproduce bug**
```
In [1]: import cudf as pd

In [2]: pd.__version__
Out[2]: '22.12.0'

In [3]: df = pd.DataFrame(columns=['a'])

In [4]: df.loc[0] = [1]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In [4], line 1
----> 1 df.loc[0] = [1]

File ~/.local/lib/python3.9/site-packages/cudf/core/dataframe.py:149, in _DataFrameIndexer.__setitem__(self, key, value)
147 if not isinstance(key, tuple):
148 key = (key, slice(None))
--> 149 return self._setitem_tuple_arg(key, value)

File ~/.local/lib/python3.9/site-packages/nvtx/nvtx.py:101, in annotate.__call__..inner(*args, **kwargs)
98 @wraps(func)
99 def inner(*args, **kwargs):
100 libnvtx_push_range(self.attributes, self.domain.handle)
--> 101 result = func(*args, **kwargs)
102 libnvtx_pop_range(self.domain.handle)
103 return result

File ~/.local/lib/python3.9/site-packages/cudf/core/dataframe.py:393, in _DataFrameLocIndexer._setitem_tuple_arg(self, key, value)
386 # Otherwise, there are two situations. The key on row axis
387 # can be a scalar or 1d. In either of the situation, the
388 # ith element in value corresponds to the ith row in
389 # the indexed object.
390 # If the key is 1d, a broadcast will happen.
391 else:
392 for i, col in enumerate(columns_df._column_names):
--> 393 self._frame[col].loc[key[0]] = value[i]

File ~/.local/lib/python3.9/site-packages/nvtx/nvtx.py:101, in annotate.__call__..inner(*args, **kwargs)
98 @wraps(func)
99 def inner(*args, **kwargs):
100 libnvtx_push_range(self.attributes, self.domain.handle)
--> 101 result = func(*args, **kwargs)
102 libnvtx_pop_range(self.domain.handle)
103 return result

File ~/.local/lib/python3.9/site-packages/cudf/core/series.py:285, in _SeriesLocIndexer.__setitem__(self, key, value)
283 value = cudf.Series(value)
284 value = value._align_to_index(self._frame.index, how="right")
--> 285 self._frame.iloc[key] = value

File ~/.local/lib/python3.9/site-packages/nvtx/nvtx.py:101, in annotate.__call__..inner(*args, **kwargs)
98 @wraps(func)
99 def inner(*args, **kwargs):
100 libnvtx_push_range(self.attributes, self.domain.handle)
--> 101 result = func(*args, **kwargs)
102 libnvtx_pop_range(self.domain.handle)
103 return result

File ~/.local/lib/python3.9/site-packages/cudf/core/series.py:236, in _SeriesIlocIndexer.__setitem__(self, key, value)
231 if to_dtype != self._frame._column.dtype:
232 self._frame._column._mimic_inplace(
233 self._frame._column.astype(to_dtype), inplace=True
234 )
--> 236 self._frame._column[key] = value

File ~/.local/lib/python3.9/site-packages/cudf/core/column/column.py:496, in ColumnBase.__setitem__(self, key, value)
494 if not isinstance(key, cudf.core.column.NumericalColumn):
495 raise ValueError(f"Invalid scatter map type {key.dtype}.")
--> 496 out = self._scatter_by_column(key, value_normalized)
498 if out:
499 self._mimic_inplace(out, inplace=True)

File ~/.local/lib/python3.9/site-packages/cudf/core/column/column.py:580, in ColumnBase._scatter_by_column(self, key, value)
576 return libcudf.copying.boolean_mask_scatter([value], [self], key)[
577 0
578 ]._with_type_metadata(self.dtype)
579 else:
--> 580 return libcudf.copying.scatter([value], key, [self])[
581 0
582 ]._with_type_metadata(self.dtype)

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

File copying.pyx:265, in cudf._lib.copying.scatter()

IndexError: index out of bounds for column of size 0

In [5]: pdf = df.to_pandas()

In [6]: pdf
Out[6]:
Empty DataFrame
Columns: [a]
Index: []

In [7]: pdf.loc[0] = [1]

In [8]: pdf
Out[8]:
a
0 1
```

**Expected behavior**
same behavior as `import pandas as pd`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.