NVIDIA / NVIDIA/cudf

[BUG] After replace [-np.inf, np.inf] with np.nan, group forward fill not working.

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

Description

**Describe the bug**
There is an inconsistency in the forward fill behavior of cudf when replacing np.inf and -np.inf values using a list. The same operation works correctly with pandas or replace np.inf and -np.inf seperately.

**Steps/Code to reproduce bug**
```
import cudf
import numpy as np

data = {
'group': ['A', 'A', 'A', 'B', 'B', 'B'],
'value': [1, -np.inf, 3, np.inf, 5, np.inf]
}

df = cudf.DataFrame(data)

print("Original DataFrame:")
print(df)

df['value'] = df['value'].replace([-np.inf, np.inf], np.nan)
df['value'] = df.groupby('group')['value'].ffill()

print("\nDataFrame after forward fill:")
print(df)

```
**Output**

> DataFrame after forward fill:
> group value
> 0 A 1.0
> 1 A NaN
> 2 A 3.0
> 3 B NaN
> 4 B 5.0
> 5 B NaN

**Expected behavior**
DataFrame after forward fill:
group value
0 A 1.0
1 A 1.0
2 A 3.0
3 B
4 B 5.0
5 B 5.0

**Environment overview (please complete the following information)**
- Environment location: CentOS
- Method of cuDF install: Conda

it works fine if seperate the replace by:
```
df['value'] = df['value'].replace(-np.inf, np.nan)
df['value'] = df['value'].replace(np.inf, np.nan)
```
or use pandas instead

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.