asddfl created SPARK-60655:
------------------------------

             Summary: pandas-on-Spark np.mod returns NaN for a finite value 
with a positive infinite divisor
                 Key: SPARK-60655
                 URL: https://issues.apache.org/jira/browse/SPARK-60655
             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), applying np.mod to a 
float64 Series containing 1.0 with positive infinity as the divisor returns 
NaN. The equivalent Pandas/NumPy operation returns 1.0 for the same input.

The example constructs a single float64 value and supplies the infinite divisor 
explicitly. Both queries complete successfully, but the pandas-on-Spark result 
introduces a missing value.

{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.mod(t0['c0'], float('inf'))
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.mod(t0['c0'], float('inf'))
print(result, flush=True)

spark.stop()
{code}

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

*Expected behavior*

np.mod(1.0, float('inf')) should return 1.0. The result should remain a float64 
Series containing the finite value, matching Pandas/NumPy.

*Actual behavior*

Pandas returns 1.0, while pandas-on-Spark returns NaN. Both result Series have 
dtype float64, so the difference concerns the computed value rather than its 
displayed dtype.



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