[ 
https://issues.apache.org/jira/browse/SPARK-60645?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144816#comment-18144816
 ] 

Ramesh Thamizhselvan commented on SPARK-60645:
----------------------------------------------

https://github.com/apache/spark/pull/60495/

> pandas-on-Spark Series constructor evaluates its Index argument as a boolean
> ----------------------------------------------------------------------------
>
>                 Key: SPARK-60645
>                 URL: https://issues.apache.org/jira/browse/SPARK-60645
>             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
>
> Constructing a pandas-on-Spark Series from an existing Series and explicitly 
> supplying that Series' own DataFrame index raises a ValueError about the 
> truth value of an Index. The equivalent Pandas constructor succeeds.
> {code:python}
> import pandas as pd
> from pyspark.sql import SparkSession
> import pyspark.pandas as ps
> t0 = pd.DataFrame({'c0': [1]})
> print("Pandas:", flush=True)
> result = pd.Series(t0['c0'], index=t0.index)
> 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]})
> print("PySpark Pandas:", flush=True)
> result = ps.Series(t0['c0'], index=t0.index)
> print(result, flush=True)
> spark.stop()
> {code}
> {code:bash}
> Pandas:
> 0    1
> Name: c0, dtype: int64
> PySpark Pandas:
> Traceback (most recent call last):
>   File "/test.py", line 24, in <module>
>     result = ps.Series(t0['c0'], index=t0.index)
>              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File 
> "/opt/conda/envs/lib/python3.11/site-packages/pyspark/pandas/series.py", line 
> 445, in __init__
>     if index:
>   File 
> "/opt/conda/envs/lib/python3.11/site-packages/pyspark/pandas/indexes/base.py",
>  line 2648, in __bool__
>     raise ValueError(
> ValueError: The truth value of a Index is ambiguous. Use a.empty, a.bool(), 
> a.item(), a.any() or a.all().
> {code}
> *Expected behavior*
> Return a Series named c0 containing the integer value 1 at index 0. The Index 
> argument should be handled without evaluating its truth value.
> *Actual behavior*
> ps.Series(t0['c0'], index=t0.index) raises ValueError: The truth value of a 
> Index is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().



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