NVIDIA / NVIDIA/cudf

[BUG] loc-based setitem with dataframe/series as rvalue doesn't match pandas

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

Description

**Describe the bug**

When performing `loc`-based setitem, pandas aligns the indices of the rvalue to match that of the lvalue. Consequently, the indexed lvalue and rvalue don't have to have the same shape (or even match indices).

```python
import pandas as pd
s = pd.Series([1, 2, 3], index=['a', 'b', 'c'])
o1 = pd.Series([5, 6, 7], index=['a', 'b', 'c'])
o2 = pd.Series([10])
s.loc[['a', 'c']] = o1
s # => [5, 2, 7]
s.loc[['a', 'b', 'c']] = o2
s # => [Nan, Nan, Nan]
```

In contrast, cudf complains in both cases.

For the former: `ValueError: Size mismatch: cannot set value of size 3 to indexing result of size 2`

For the latter: `align_to_index` fails (because the int index cannot be merged with the string index). If `o2` has a string index, it fails because the pruned aligned series is not the right length.

**Expected behavior**

Probably this should behave as pandas. I think the case where the index types are different will probably need to be special-cased.

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.