0ac5c16177
### What changes were proposed in this pull request? Support arithmetic operations against bool IndexOpsMixin. ### Why are the changes needed? Existing binary operations of bool IndexOpsMixin in Koalas do not match pandas’ behaviors. pandas take True as 1, False as 0 when dealing with numeric values, numeric collections, and numeric Series/Index; whereas Koalas raises an AnalysisException no matter what the binary operation is. We aim to match pandas' behaviors. ### Does this PR introduce _any_ user-facing change? Yes. Before the change: ```py >>> import pyspark.pandas as ps >>> psser = ps.Series([True, True, False]) >>> psser + 1 Traceback (most recent call last): ... TypeError: Addition can not be applied to booleans. >>> 1 + psser Traceback (most recent call last): ... TypeError: Addition can not be applied to booleans. >>> from pyspark.pandas.config import set_option >>> set_option("compute.ops_on_diff_frames", True) >>> psser + ps.Series([1, 2, 3]) Traceback (most recent call last): ... TypeError: Addition can not be applied to booleans. >>> ps.Series([1, 2, 3]) + psser Traceback (most recent call last): ... TypeError: addition can not be applied to given types. ``` After the change: ```py >>> import pyspark.pandas as ps >>> psser = ps.Series([True, True, False]) >>> psser + 1 0 2 1 2 2 1 dtype: int64 >>> 1 + psser 0 2 1 2 2 1 dtype: int64 >>> from pyspark.pandas.config import set_option >>> set_option("compute.ops_on_diff_frames", True) >>> psser + ps.Series([1, 2, 3]) 0 2 1 3 2 3 dtype: int64 >>> ps.Series([1, 2, 3]) + psser 0 2 1 3 2 3 dtype: int64 ``` ### How was this patch tested? Unit tests. Closes #32611 from xinrong-databricks/datatypeop_arith_bool. Authored-by: Xinrong Meng <xinrong.meng@databricks.com> Signed-off-by: Takuya UESHIN <ueshin@databricks.com> |
||
---|---|---|
.. | ||
data_type_ops | ||
indexes | ||
plot | ||
__init__.py | ||
test_categorical.py | ||
test_config.py | ||
test_csv.py | ||
test_dataframe.py | ||
test_dataframe_conversion.py | ||
test_dataframe_spark_io.py | ||
test_default_index.py | ||
test_expanding.py | ||
test_extension.py | ||
test_frame_spark.py | ||
test_groupby.py | ||
test_indexing.py | ||
test_indexops_spark.py | ||
test_internal.py | ||
test_namespace.py | ||
test_numpy_compat.py | ||
test_ops_on_diff_frames.py | ||
test_ops_on_diff_frames_groupby.py | ||
test_ops_on_diff_frames_groupby_expanding.py | ||
test_ops_on_diff_frames_groupby_rolling.py | ||
test_repr.py | ||
test_reshape.py | ||
test_rolling.py | ||
test_series.py | ||
test_series_conversion.py | ||
test_series_datetime.py | ||
test_series_string.py | ||
test_sql.py | ||
test_stats.py | ||
test_typedef.py | ||
test_utils.py | ||
test_window.py |