[ 
https://issues.apache.org/jira/browse/SPARK-60562?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated SPARK-60562:
-----------------------------------
    Labels: pull-request-available  (was: )

> pandas-on-Spark assign broadcasts a callable-returned ndarray into every row
> ----------------------------------------------------------------------------
>
>                 Key: SPARK-60562
>                 URL: https://issues.apache.org/jira/browse/SPARK-60562
>             Project: Spark
>          Issue Type: Bug
>          Components: Pandas API on Spark, PySpark
>    Affects Versions: 4.2.0
>         Environment: Platform: Ubuntu 24.04 Linux-6.17.0-29-generic x86_64
> Python: 3.11.17
> pyspark 4.2.0
> findspark 2.0.1
> pandas 3.0.6
> numpy 2.4.6
>            Reporter: asddfl
>            Priority: Critical
>              Labels: pull-request-available
>
> A callable passed to DataFrame.assign returns an ndarray from an existing 
> column. Pandas assigns its elements to the corresponding rows, producing 
> scalar c1 values 1 and 2. pandas-on-Spark accepts the callable but instead 
> stores the entire [1, 2] array in each c1 cell.
> The operation succeeds without an exception while changing the shape and 
> meaning of each assigned value.
> {code:python}
> import pandas as pd
> from pyspark.sql import SparkSession
> import pyspark.pandas as ps
> t0 = pd.DataFrame({'c0': [1, 2]})
> print("Pandas:", flush=True)
> result = t0.assign(c1=lambda t1: t1['c0'].to_numpy())
> print(result, flush=True)
> spark = (
>     SparkSession.builder
>     .master("local[2]")
>     .config("spark.sql.ansi.enabled", "false")
>     .config("spark.sql.shuffle.partitions", "2")
>     .getOrCreate()
> )
> ps.set_option("compute.ops_on_diff_frames", True)
> t0 = ps.DataFrame({'c0': [1, 2]})
> print("PySpark Pandas:", flush=True)
> result = t0.assign(c1=lambda t1: t1['c0'].to_numpy())
> print(result, flush=True)
> spark.stop()
> {code}
> {code:bash}
> Pandas:
>    c0  c1
> 0   1   1
> 1   2   2
> PySpark Pandas:
>    c0      c1
> 0   1  [1, 2]
> 1   2  [1, 2]
> {code}
> *Expected behavior*
> If this callable output is supported, return the Pandas-equivalent scalar c1 
> values 1 and 2. If position-based ndarray assignment is unsupported, reject 
> the evaluated callable output with a clear error. It should not silently turn 
> the whole array into a value repeated in every row.
> *Actual behavior*
> Pandas returns rows (c0=1, c1=1) and (c0=2, c1=2). pandas-on-Spark returns 
> rows (c0=1, c1=[1, 2]) and (c0=2, c1=[1, 2]).
> *Reproduction notes*
> Inspection of the installed DataFrame._assign implementation shows that it 
> validates the assignee before evaluating a callable. The resulting ndarray is 
> not checked again and reaches the literal-value construction path. This 
> report concerns inconsistent result-type validation and silent array 
> broadcasting; it does not assume that positional ndarray assignment is an API 
> support promise.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to