asddfl created SPARK-60654:
------------------------------
Summary: pandas-on-Spark integer floor division produces float64
and breaks a subsequent np.gcd
Key: SPARK-60654
URL: https://issues.apache.org/jira/browse/SPARK-60654
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
For an explicitly int32 Series containing 1, integer floor division by the same
Series produces a floating-point operand under the pandas API on Spark. A
subsequent np.gcd call then receives an int32 array and a float64 array and
raises a NumPy type error. Pandas keeps integer operands and succeeds.
{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]}, dtype='int32')
print("Pandas:", flush=True)
result = np.gcd(t0['c0'].to_numpy(), (t0['c0'] // t0['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()
)
t0 = ps.DataFrame({'c0': [1]}, dtype='int32')
print("PySpark Pandas:", flush=True)
result = np.gcd(t0['c0'].to_numpy(), (t0['c0'] // t0['c0']).to_numpy())
print(result, flush=True)
spark.stop()
{code}
{code:bash}
Pandas:
[1]
PySpark Pandas:
Traceback (most recent call last):
File "/test.py", line 25, in <module>
result = np.gcd(t0['c0'].to_numpy(), (t0['c0'] // t0['c0']).to_numpy())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy._core._exceptions._UFuncNoLoopError: ufunc 'gcd' did not contain a loop
with signature matching types (<class 'numpy.dtypes.Int32DType'>, <class
'numpy.dtypes.Float64DType'>) -> None
{code}
*Expected behavior*
The integer floor-division result should remain compatible with the integer
input, allowing np.gcd to return an integer array containing 1, as in Pandas.
*Actual behavior*
The call raises numpy._core._exceptions._UFuncNoLoopError: ufunc 'gcd' did not
contain a loop with signature matching types (Int32DType, Float64DType). The
second operand is obtained from the integer floor-division result via
to_numpy().
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]