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

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

> pandas-on-Spark sum does not skip a NaN generated at runtime by cos(inf)
> ------------------------------------------------------------------------
>
>                 Key: SPARK-60657
>                 URL: https://issues.apache.org/jira/browse/SPARK-60657
>             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
>
> The default sum aggregation over np.cos of a float64 Series behaves 
> differently in Pandas and the pandas API on Spark. For input [inf, 0.0], cos 
> produces a NaN and the finite value 1.0. Pandas sum skips the NaN and returns 
> 1.0, but pandas-on-Spark returns NaN.
> Both queries complete successfully. The example isolates aggregation of a 
> computed NaN.
> {code:python}
> import pandas as pd
> import numpy as np
> from pyspark.sql import SparkSession
> import pyspark.pandas as ps
> t0 = pd.DataFrame({'c0': [float('inf'), 0.0]})
> print("Pandas:", flush=True)
> result = np.cos(t0['c0']).sum()
> 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': [float('inf'), 0.0]})
> print("PySpark Pandas:", flush=True)
> result = np.cos(t0['c0']).sum()
> print(result, flush=True)
> spark.stop()
> {code}
> {code:bash}
> Pandas:
> 1.0
> PySpark Pandas:
> nan
> {code}
> *Expected behavior*
> The default sum(skipna=True) behavior should skip the generated NaN and 
> return 1.0, matching Pandas.
> *Actual behavior*
> Pandas prints 1.0, while pandas-on-Spark prints nan.



--
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