8d8b4aabc3
### 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 ``` Again, this syntax remains experimental and this is a non-standard way apart from Python standard. We should migrate to proper typing once pandas supports it like `numpy.typing`. ### 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. Closes #34007 from HyukjinKwon/SPARK-36710. Authored-by: Hyukjin Kwon <gurwls223@apache.org> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org> |
||
---|---|---|
.. | ||
docs | ||
lib | ||
pyspark | ||
test_coverage | ||
test_support | ||
.coveragerc | ||
.gitignore | ||
MANIFEST.in | ||
mypy.ini | ||
pylintrc | ||
README.md | ||
run-tests | ||
run-tests-with-coverage | ||
run-tests.py | ||
setup.cfg | ||
setup.py |
Apache Spark
Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R, and an optimized engine that supports general computation graphs for data analysis. It also supports a rich set of higher-level tools including Spark SQL for SQL and DataFrames, pandas API on Spark for pandas workloads, MLlib for machine learning, GraphX for graph processing, and Structured Streaming for stream processing.
Online Documentation
You can find the latest Spark documentation, including a programming guide, on the project web page
Python Packaging
This README file only contains basic information related to pip installed PySpark. This packaging is currently experimental and may change in future versions (although we will do our best to keep compatibility). Using PySpark requires the Spark JARs, and if you are building this from source please see the builder instructions at "Building Spark".
The Python packaging for Spark is not intended to replace all of the other use cases. This Python packaged version of Spark is suitable for interacting with an existing cluster (be it Spark standalone, YARN, or Mesos) - but does not contain the tools required to set up your own standalone Spark cluster. You can download the full version of Spark from the Apache Spark downloads page.
NOTE: If you are using this with a Spark standalone cluster you must ensure that the version (including minor version) matches or you may experience odd errors.
Python Requirements
At its core PySpark depends on Py4J, but some additional sub-packages have their own extra requirements for some features (including numpy, pandas, and pyarrow). See also Dependencies for production, and dev/requirements.txt for development.