asddfl created SPARK-60656:
------------------------------

             Summary: pandas-on-Spark np.maximum fails to propagate a missing 
operand generated by log
                 Key: SPARK-60656
                 URL: https://issues.apache.org/jira/browse/SPARK-60656
             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


When using the pandas API on Spark (pyspark.pandas), np.maximum does not 
preserve the missing result of np.log(-1.0). Pandas/NumPy returns NaN, while 
pandas-on-Spark returns the other operand, -1.0.

The example contains one float64 value and computes the missing operand at 
runtime. Both queries complete successfully, but the result changes from 
missing to a finite number.

{code:python}
import pandas as pd
import numpy as np
from pyspark.sql import SparkSession
import pyspark.pandas as ps

t0 = pd.DataFrame({'c0': [-1.0]})

print("Pandas:", flush=True)
result = np.maximum(np.log(t0['c0']), t0['c0'])
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.0]})

print("PySpark Pandas:", flush=True)
result = np.maximum(np.log(t0['c0']), t0['c0'])
print(result, flush=True)

spark.stop()
{code}

{code:bash}
Pandas:
0   NaN
Name: c0, dtype: float64
PySpark Pandas:
0   -1.0
Name: c0, dtype: float64
{code}

*Expected behavior*

np.maximum(np.log(-1.0), -1.0) should propagate the missing operand and return 
NaN, matching Pandas/NumPy.

*Actual behavior*

Pandas prints NaN. pandas-on-Spark prints -1.0. Both result Series have dtype 
float64.




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