ntjohnson1 commented on PR #1302:
URL: 
https://github.com/apache/datafusion-python/pull/1302#issuecomment-3512181128

   Ran through a couple usages I hit often and looks much nicer! Extracting a 
scalar as a python type is still a little verbose but dramatically better than 
before.
   
   ```python
   import datafusion as dfn
   from datafusion import col
   import pyarrow as pa
   
   def main():
       ctx = dfn.SessionContext()
   
       df = ctx.from_pydict({
           "a": [3, 1, 2],
           "b": [4, 6, 5]
       })
       before_result = pa.table(df.select("a"))["a"].to_numpy()
       result = df.collect_column("a").to_numpy()
       print(f" {before_result=}\n\t{result=}")
   
       # Without as_py
       df_of_interest = df.filter(col("b") > 5)
       before_result = pa.table(df_of_interest.select("b"))["b"][0]
       result = df_of_interest.collect_column("b")[0]
       print(f" {before_result=}\n\t{result=}")
   
       # With as_py
       df_of_interest = df.filter(col("b") > 5)
       before_result = pa.table(df_of_interest.select("b"))["b"][0].as_py()
       result = df_of_interest.collect_column("b")[0].as_py()
       print(f" {before_result=}\n\t{result=}")
   
   if __name__ == "__main__":
       main()
   ```
   
   ```console
    before_result=array([3, 1, 2])
           result=array([3, 1, 2])
    before_result=<pyarrow.Int64Scalar: 6>
           result=<pyarrow.Int64Scalar: 6>
    before_result=6
           result=6
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to