Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-19454

Improve DataFrame.replace API

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.0, 1.6.0, 2.0.0, 2.1.0, 2.2.0
    • Fix Version/s: 2.2.0
    • Component/s: PySpark, SQL
    • Labels:
      None

      Description

      Current implementation suffers from following issues:

      • It is possible to use dict as to_replace, but we cannot skip or use None as the value value (although it is ignored). This requires passing "magic" values:
        df = sc.parallelize([("Alice", 1, 3.0)]).toDF()
        df.replace({"Alice": "Bob"}, 1)
        
      • Code doesn't check if provided types are correct. This can lead to exception in Py4j (harder to diagnose):
         df.replace({"Alice": 1}, 1)
        

        or silent failures (with bundled Py4j version):

         df.replace({1: 2, 3.0: 4.1, "a": "b"}, 1)
        

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                zero323 Maciej Szymkiewicz
                Reporter:
                zero323 Maciej Szymkiewicz
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: