Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions python/docs/source/user_guide/ansi_migration_guide.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,82 @@
"```"
]
},
{
"cell_type": "markdown",
"id": "a9ceb6cb-3bc4-4c23-b74b-84e60fd64e11",
"metadata": {},
"source": [
"### Invalid Mixed-Type Operations\n",
"**ANSI off:** Spark implicitly coerces so these operations succeed.\n",
"\n",
"**ANSI on:** Behaves like pandas, such operations are disallowed and raise errors.\n",
"\n",
"Operation types that show behavior changes under ANSI mode:\n",
"\n",
"- **Decimal–Float Arithmetic**: `/`, `//`, `*`, `%` \n",
"- **Boolean vs. None**: `|`, `&`, `^`"
]
},
{
"cell_type": "markdown",
"id": "2a8d5705-11ea-458c-8528-c7b1b7c88472",
"metadata": {},
"source": [
"Example: Decimal–Float Arithmetic\n",
"```python\n",
">>> import decimal\n",
">>> pser = pd.Series([decimal.Decimal(1), decimal.Decimal(2)])\n",
">>> psser = ps.from_pandas(pser)\n",
"\n",
"# ANSI on\n",
">>> spark.conf.set(\"spark.sql.ansi.enabled\", True)\n",
">>> psser * 0.1\n",
"Traceback (most recent call last):\n",
"...\n",
"TypeError: Multiplication can not be applied to given types.\n",
"\n",
"# ANSI off\n",
">>> spark.conf.set(\"spark.sql.ansi.enabled\", False)\n",
">>> psser * 0.1\n",
"0 0.1\n",
"1 0.2\n",
"dtype: float64\n",
"\n",
"# Pandas\n",
">>> pser * 0.1\n",
"...\n",
"TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "0d2b8268-4b98-4239-95db-5269f9c658d2",
"metadata": {},
"source": [
"Example: Boolean vs. None\n",
"```python\n",
"# ANSI on\n",
">>> spark.conf.set(\"spark.sql.ansi.enabled\", True)\n",
">>> ps.Series([True, False]) | None\n",
"Traceback (most recent call last):\n",
"...\n",
"TypeError: OR can not be applied to given types.\n",
"\n",
"# ANSI off\n",
">>> spark.conf.set(\"spark.sql.ansi.enabled\", False)\n",
">>> ps.Series([True, False]) | None\n",
"0 False \n",
"1 False\n",
"dtype: bool\n",
"\n",
"# Pandas\n",
">>> pd.Series([True, False]) | None\n",
"...\n",
"TypeError: unsupported operand type(s) for |: 'bool' and 'NoneType'\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "fe146afd",
Expand Down