HyukjinKwon opened a new pull request #34007:
URL: https://github.com/apache/spark/pull/34007


   ### What changes were proposed in this pull request?
   
   This PR proposes the new syntax introduced in 
https://github.com/apache/spark/pull/33954. Namely, users now can specify the 
index type and name as below:
   
   ```python
   import pandas as pd
   import pyspark.pandas as ps
   def transform(pdf) -> pd.DataFrame[int, [int, int]]:
       pdf['A'] = pdf.id + 1
       return pdf
   
   ps.range(5).koalas.apply_batch(transform)
   ```
   
   ```
      c0  c1
   0   0   1
   1   1   2
   2   2   3
   3   3   4
   4   4   5
   ```
   
   ```python
   import pandas as pd
   import pyspark.pandas as ps
   def transform(pdf) -> pd.DataFrame[("index", int), [("a", int), ("b", int)]]:
       pdf['A'] = pdf.id * pdf.id
       return pdf
   
   ps.range(5).koalas.apply_batch(transform)
   ```
   
   ```
          a   b
   index
   0      0   0
   1      1   1
   2      2   4
   3      3   9
   4      4  16
   ```
   
   ### Why are the changes needed?
   
   The rationale is described in https://github.com/apache/spark/pull/33954. In 
order to avoid unnecessary computation for default index or schema inference. 
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, this PR affects the following APIs:
   
   - `DataFrame.apply(..., axis=1)`
   - `DataFrame.groupby.apply(...)`
   - `DataFrame.pandas_on_spark.transform_batch(...)`
   - `DataFrame.pandas_on_spark.apply_batch(...)`
   
   Now they can specify the index type with the new syntax below:
   
   ```
   DataFrame[index_type, [type, ...]]
   DataFrame[(index_name, index_type), [(name, type), ...]]
   DataFrame[dtype instance, dtypes instance]
   DataFrame[(index_name, index_type), zip(names, types)]
   ```
   
   ### How was this patch tested?
   
   Manually tested, and unittests were added.
   


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