@@ -260,10 +260,6 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
260260
261261 /**
262262 * Replaces values matching keys in `replacement` map with the corresponding values.
263- * Key and value of `replacement` map must have the same type, and
264- * can only be doubles, strings or booleans.
265- * `replacement` map value can have null.
266- * If `col` is "*", then the replacement is applied on all string columns or numeric columns.
267263 *
268264 * {{{
269265 * import com.google.common.collect.ImmutableMap;
@@ -278,8 +274,11 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
278274 * df.na.replace("*", ImmutableMap.of("UNKNOWN", "unnamed"));
279275 * }}}
280276 *
281- * @param col name of the column to apply the value replacement
282- * @param replacement value replacement map, as explained above
277+ * @param col name of the column to apply the value replacement. If `col` is "*",
278+ * replacement is applied on all string, numeric or boolean columns.
279+ * @param replacement value replacement map. Key and value of `replacement` map must have
280+ * the same type, and can only be doubles, strings or booleans.
281+ * The map value can have nulls.
283282 *
284283 * @since 1.3.1
285284 */
@@ -289,9 +288,6 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
289288
290289 /**
291290 * Replaces values matching keys in `replacement` map with the corresponding values.
292- * Key and value of `replacement` map must have the same type, and
293- * can only be doubles, strings or booleans.
294- * `replacement` map value can have null.
295291 *
296292 * {{{
297293 * import com.google.common.collect.ImmutableMap;
@@ -303,8 +299,11 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
303299 * df.na.replace(new String[] {"firstname", "lastname"}, ImmutableMap.of("UNKNOWN", "unnamed"));
304300 * }}}
305301 *
306- * @param cols list of columns to apply the value replacement
307- * @param replacement value replacement map, as explained above
302+ * @param cols list of columns to apply the value replacement. If `col` is "*",
303+ * replacement is applied on all string, numeric or boolean columns.
304+ * @param replacement value replacement map. Key and value of `replacement` map must have
305+ * the same type, and can only be doubles, strings or booleans.
306+ * The map value can have nulls.
308307 *
309308 * @since 1.3.1
310309 */
@@ -314,11 +313,6 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
314313
315314 /**
316315 * (Scala-specific) Replaces values matching keys in `replacement` map.
317- * Key and value of `replacement` map must have the same type, and
318- * can only be doubles, strings or booleans.
319- * `replacement` map value can have null.
320- * If `col` is "*",
321- * then the replacement is applied on all string columns , numeric columns or boolean columns.
322316 *
323317 * {{{
324318 * // Replaces all occurrences of 1.0 with 2.0 in column "height".
@@ -331,8 +325,11 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
331325 * df.na.replace("*", Map("UNKNOWN" -> "unnamed"));
332326 * }}}
333327 *
334- * @param col name of the column to apply the value replacement
335- * @param replacement value replacement map, as explained above
328+ * @param col name of the column to apply the value replacement. If `col` is "*",
329+ * replacement is applied on all string, numeric or boolean columns.
330+ * @param replacement value replacement map. Key and value of `replacement` map must have
331+ * the same type, and can only be doubles, strings or booleans.
332+ * The map value can have nulls.
336333 *
337334 * @since 1.3.1
338335 */
@@ -346,9 +343,6 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
346343
347344 /**
348345 * (Scala-specific) Replaces values matching keys in `replacement` map.
349- * Key and value of `replacement` map must have the same type, and
350- * can only be doubles, strings or booleans.
351- * `replacement` map value can have null.
352346 *
353347 * {{{
354348 * // Replaces all occurrences of 1.0 with 2.0 in column "height" and "weight".
@@ -358,8 +352,11 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
358352 * df.na.replace("firstname" :: "lastname" :: Nil, Map("UNKNOWN" -> "unnamed"));
359353 * }}}
360354 *
361- * @param cols list of columns to apply the value replacement
362- * @param replacement value replacement map, as explained above
355+ * @param cols list of columns to apply the value replacement. If `col` is "*",
356+ * replacement is applied on all string, numeric or boolean columns.
357+ * @param replacement value replacement map. Key and value of `replacement` map must have
358+ * the same type, and can only be doubles, strings or booleans.
359+ * The map value can have nulls.
363360 *
364361 * @since 1.3.1
365362 */
@@ -370,8 +367,8 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
370367 return df
371368 }
372369
373- // replacementMap is either Map[String, String], Map[Double, Double], Map[Boolean,Boolean]
374- // while value can have null
370+ // Convert the NumericType in replacement map to DoubleType,
371+ // while leaving StringType, BooleanType and null untouched.
375372 val replacementMap : Map [_, _] = replacement.map {
376373 case (k, v : String ) => (k, v)
377374 case (k, v : Boolean ) => (k, v)
@@ -381,7 +378,9 @@ final class DataFrameNaFunctions private[sql](df: DataFrame) {
381378 case (k, v) => (convertToDouble(k), convertToDouble(v))
382379 }
383380
384- // targetColumnType is either DoubleType or StringType or BooleanType
381+ // targetColumnType is either DoubleType, StringType or BooleanType,
382+ // depending on the type of first key in replacement map.
383+ // Only fields of targetColumnType will perform replacement.
385384 val targetColumnType = replacement.head._1 match {
386385 case _ : jl.Double | _ : jl.Float | _ : jl.Integer | _ : jl.Long => DoubleType
387386 case _ : jl.Boolean => BooleanType
0 commit comments