NVIDIA / NVIDIA/cudf

[BUG] Random sampling with cupy does not support these inputs

Open
#12,344 4 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

Weighted sampling with cudf series is documented as supported but throws the following error

Repro:
```
a = cudf.Series(range(100))
a.sample(n=10, weights=a.values_host, random_state=0)

or

a = cudf.Series(range(100))
a.sample(n=10, weights=a.values_host, random_state=0)

```

Exception:
```
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
File /conda/envs/rapids-22.12/lib/python3.9/site-packages/cudf/core/indexed_frame.py:2952, in IndexedFrame._sample_axis_0(self, n, weights, replace, random_state, ignore_index)
2951 try:
-> 2952 gather_map_array = random_state.choice(
2953 len(self), size=n, replace=replace, p=weights
2954 )
2955 except NotImplementedError as e:

File /conda/envs/rapids-22.12/lib/python3.9/site-packages/cupy/random/_generator.py:1066, in RandomState.choice(self, a, size, replace, p)
1065 if not replace:
-> 1066 raise NotImplementedError
1068 if p is not None:

NotImplementedError:

The above exception was the direct cause of the following exception:

NotImplementedError Traceback (most recent call last)
Cell In [25], line 2
1 a = cudf.Series(range(100))
----> 2 a.sample(n=10, weights=a, random_state=0)

File /conda/envs/rapids-22.12/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 /conda/envs/rapids-22.12/lib/python3.9/site-packages/cudf/core/indexed_frame.py:2930, in IndexedFrame.sample(self, n, frac, replace, weights, random_state, axis, ignore_index)
2927 weights = weights / weights.sum()
2929 if axis == 0:
-> 2930 return self._sample_axis_0(
2931 n, weights, replace, random_state, ignore_index
2932 )
2933 else:
2934 if isinstance(random_state, cp.random.RandomState):

File /conda/envs/rapids-22.12/lib/python3.9/site-packages/cudf/core/indexed_frame.py:2956, in IndexedFrame._sample_axis_0(self, n, weights, replace, random_state, ignore_index)
2952 gather_map_array = random_state.choice(
2953 len(self), size=n, replace=replace, p=weights
2954 )
2955 except NotImplementedError as e:
-> 2956 raise NotImplementedError(
2957 "Random sampling with cupy does not support these inputs."
2958 ) from e
2960 return self._gather(
2961 cudf.core.column.as_column(gather_map_array),
2962 keep_index=not ignore_index,
2963 check_bounds=False,
2964 )

NotImplementedError: Random sampling with cupy does not support these inputs.
```

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.