Automatic Data Promotion from Int to Float for dt.replace function
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 164
- Avg merge
- 7h 31m
- Merged PRs (30d)
- 1
Description
- Describe what feature you would like to see implemented.
The ``replace`` function should automatically promote integers to floats, if a float is used in an integer column.
- If possible, give an example of how it may look in the code and what result
will be produced.
Example:
```python
df=dt.Frame({"Date":["8/4/2020","8/4/2020","8/4/2020","8/4/2020","8/4/2020"],
"Weight":[35,40,30,50,50],
"Subportfolio":["Portfolio1","Portfolio2","Portfolio3","Portfolio4","Portfolio5"],
"Portfolio Code":[1,1,1,2,2]})
df
Date Weight Subportfolio Portfolio Code
0 8/4/2020 35 Portfolio1 1
1 8/4/2020 40 Portfolio2 1
2 8/4/2020 30 Portfolio3 1
3 8/4/2020 50 Portfolio4 2
4 8/4/2020 50 Portfolio5 2
df.replace(1, 1.0)
# one scenario where a user might want to replace ints with floats is a column with nulls,
# where you have the mean of a list of numbers, but the mean is a float.
# Replacing the null entries in that column with the float will trigger an error as below :
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
----> 1 df.replace(1, 1.0)
TypeError: Cannot replace integer value 1 with a value of type
```
References #2663
Contributor guide
Assessment
This issue has not been assessed yet.