Skip to content

Commit

Permalink
[SPARK-21658][SQL][PYSPARK] Add default None for value in na.replace …
Browse files Browse the repository at this point in the history
…in PySpark

## What changes were proposed in this pull request?
JIRA issue: https://issues.apache.org/jira/browse/SPARK-21658

Add default None for value in `na.replace` since `Dataframe.replace` and `DataframeNaFunctions.replace` are alias.

The default values are the same now.
```
>>> df = sqlContext.createDataFrame([('Alice', 10, 80.0)])
>>> df.replace({"Alice": "a"}).first()
Row(_1=u'a', _2=10, _3=80.0)
>>> df.na.replace({"Alice": "a"}).first()
Row(_1=u'a', _2=10, _3=80.0)
```

## How was this patch tested?
Existing tests.

cc viirya

Author: byakuinss <grace.chinhanyu@gmail.com>

Closes #18895 from byakuinss/SPARK-21658.
  • Loading branch information
chihhanyu authored and HyukjinKwon committed Aug 14, 2017
1 parent 6847e93 commit 0fcde87
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion python/pyspark/sql/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,16 @@ def replace(self, to_replace, value=None, subset=None):
|null| null|null|
+----+------+----+
>>> df4.na.replace('Alice').show()
+----+------+----+
| age|height|name|
+----+------+----+
| 10| 80|null|
| 5| null| Bob|
|null| null| Tom|
|null| null|null|
+----+------+----+
>>> df4.na.replace(['Alice', 'Bob'], ['A', 'B'], 'name').show()
+----+------+----+
| age|height|name|
Expand Down Expand Up @@ -1837,7 +1847,7 @@ def fill(self, value, subset=None):

fill.__doc__ = DataFrame.fillna.__doc__

def replace(self, to_replace, value, subset=None):
def replace(self, to_replace, value=None, subset=None):
return self.df.replace(to_replace, value, subset)

replace.__doc__ = DataFrame.replace.__doc__
Expand Down

0 comments on commit 0fcde87

Please sign in to comment.