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

Michael Souder commented on SPARK-24835:
----------------------------------------

Liang-Chi, your first block actually fails for me with an AnalysisException:
{code:python}
df2 = df.drop('c')
df2.where(df['c'] < 6).show()

Py4JJavaError: An error occurred while calling o11586.filter.
: org.apache.spark.sql.AnalysisException: Resolved attribute(s) c#87962L 
missing from a#87960L,b#87961L in operator !Filter (c#87962L < cast(6 as 
bigint)).;;
{code}
But I was more interested in the difference between resolving a column with the 
bracket interface df['c'] and with F.col('c') and why one can see a previously 
dropped column and the other can't.  You mention that drop adds a projection on 
top of the original dataset.  So accessing the column with brackets applies 
after the projection, but accessing with F.col() can see before the projection?

> col function ignores drop
> -------------------------
>
>                 Key: SPARK-24835
>                 URL: https://issues.apache.org/jira/browse/SPARK-24835
>             Project: Spark
>          Issue Type: Bug
>          Components: PySpark
>    Affects Versions: 2.3.0
>         Environment: Spark 2.3.0
> Python 3.5.3
>            Reporter: Michael Souder
>            Priority: Minor
>
> Not sure if this is a bug or user error, but I've noticed that accessing 
> columns with the col function ignores a previous call to drop.
> {code}
> import pyspark.sql.functions as F
> df = spark.createDataFrame([(1,3,5), (2, None, 7), (0, 3, 2)], ['a', 'b', 
> 'c'])
> df.show()
> +---+----+---+
> |  a|   b|  c|
> +---+----+---+
> |  1|   3|  5|
> |  2|null|  7|
> |  0|   3|  2|
> +---+----+---+
> df = df.drop('c')
> # the col function is able to see the 'c' column even though it has been 
> dropped
> df.where(F.col('c') < 6).show()
> +---+---+
> |  a|  b|
> +---+---+
> |  1|  3|
> |  0|  3|
> +---+---+
> # trying the same with brackets on the data frame fails with the expected 
> error
> df.where(df['c'] < 6).show()
> Py4JJavaError: An error occurred while calling o36909.apply.
> : org.apache.spark.sql.AnalysisException: Cannot resolve column name "c" 
> among (a, b);{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to