NVIDIA / NVIDIA/cudf

[FEA] Support objects with default values in Series.map

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

Description

**Is your feature request related to a problem? Please describe.**
I'd like for cuDF to support 'defaultdict' like objects in the Series.map method. There is currently a NotImplementedError which contrasts from the Pandas implementation of Series.map

**Describe the solution you'd like**
An implementation of Series.map that converts values that are not found in the dict to a default value, if the dict has a default value (e.g. defaultdict).

**Additional context**
With Pandas an example of this looks like
```
>>>p1 = pd.Series(['cat', 'dog', np.nan, 'rabbit'])
>>>from collections import defaultdict
>>>t = defaultdict(lambda: 'bird')
>>> t['cat'] = 'kitten'
>>> t['dog'] = 'puppy'
>>> p1.map(t)
0 kitten
1 puppy
2 bird
3 bird
dtype: object
```
With cuDF currently we get the following
```
>>> s = cudf.Series(['cat', 'dog', np.nan, 'rabbit'])
>>>s.map(t)

Traceback (most recent call last):
File "", line 1, in
File "/home/nfs/mmhangami/marlene/rapids/cudf/python/cudf/cudf/core/series.py", line 878, in map
"default values in dicts are currently not supported."
NotImplementedError: default values in dicts are currently not supported.
```

for additional context see [pandas.Series.map](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.map.html) and PR #6459

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.