Commit 528f3a7
[SPARK-53301][PYTHON] Differentiate type hints of Pandas UDF and Arrow UDF
### What changes were proposed in this pull request?
Differentiate type hints of Pandas UDF and Arrow UDF
### Why are the changes needed?
The `arrow_udf` can works with a pandas udf, and the `pandas_udf` can works with a arrow udf, because the eval type inference didn't differentiate the pandas udf and arrow udf.
But this is supposed to fail.
before:
```
In [1]: import pyarrow as pa
...:
...: from pyspark.sql import functions as sf
...: from pyspark.sql.functions import arrow_udf, pandas_udf
...:
...: df = spark.range(10).withColumn("v", sf.col("id") + 1)
...:
...:
...: pandas_udf("long")
...: def multiply_arrow_func(a: pa.Array, b: pa.Array) -> pa.Array:
...: assert isinstance(a, pa.Array)
...: assert isinstance(b, pa.Array)
...: return pa.compute.multiply(a, b)
...:
...:
In [2]: df.select("id", "v", multiply_arrow_func("id", "v").alias("m")).show()
...:
+---+---+---+
| id| v| m|
+---+---+---+
| 0| 1| 0|
| 1| 2| 2|
| 2| 3| 6|
| 3| 4| 12|
| 4| 5| 20|
| 5| 6| 30|
| 6| 7| 42|
| 7| 8| 56|
| 8| 9| 72|
| 9| 10| 90|
+---+---+---+
```
after
```
In [2]: ...: pandas_udf("long")
...: ...: def multiply_arrow_func(a: pa.Array, b: pa.Array) -> pa.Array:
...: ...: assert isinstance(a, pa.Array)
...: ...: assert isinstance(b, pa.Array)
...: ...: return pa.compute.multiply(a, b)
...:
---------------------------------------------------------------------------
PySparkNotImplementedError Traceback (most recent call last)
...
PySparkNotImplementedError: [UNSUPPORTED_SIGNATURE] Unsupported signature: (a: pyarrow.lib.Array, b: pyarrow.lib.Array) -> pyarrow.lib.Array.
```
### Does this PR introduce _any_ user-facing change?
no, arrow_udf is not yet released
### How was this patch tested?
new tests
### Was this patch authored or co-authored using generative AI tooling?
no
Closes apache#52054 from zhengruifeng/arrow_pandas_type_hint.
Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>1 parent 64bd0e2 commit 528f3a7
File tree
4 files changed
+161
-56
lines changed- python/pyspark/sql
- pandas
- tests
- arrow
- pandas
4 files changed
+161
-56
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
807 | 807 | | |
808 | 808 | | |
809 | 809 | | |
810 | | - | |
| 810 | + | |
811 | 811 | | |
812 | 812 | | |
813 | 813 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
44 | 38 | | |
45 | 39 | | |
46 | 40 | | |
47 | 41 | | |
48 | | - | |
| 42 | + | |
49 | 43 | | |
50 | 44 | | |
51 | | - | |
52 | 45 | | |
53 | 46 | | |
54 | | - | |
55 | 47 | | |
56 | 48 | | |
57 | 49 | | |
| |||
85 | 77 | | |
86 | 78 | | |
87 | 79 | | |
88 | | - | |
89 | | - | |
90 | | - | |
| 80 | + | |
| 81 | + | |
91 | 82 | | |
92 | 83 | | |
93 | 84 | | |
| |||
110 | 101 | | |
111 | 102 | | |
112 | 103 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 104 | + | |
| 105 | + | |
128 | 106 | | |
129 | 107 | | |
130 | 108 | | |
| |||
143 | 121 | | |
144 | 122 | | |
145 | 123 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 124 | + | |
| 125 | + | |
158 | 126 | | |
159 | 127 | | |
160 | 128 | | |
| |||
173 | 141 | | |
174 | 142 | | |
175 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
176 | 221 | | |
177 | 222 | | |
178 | 223 | | |
179 | 224 | | |
180 | 225 | | |
181 | 226 | | |
182 | 227 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 228 | + | |
195 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
196 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
197 | 272 | | |
198 | 273 | | |
199 | 274 | | |
200 | 275 | | |
201 | 276 | | |
| 277 | + | |
| 278 | + | |
202 | 279 | | |
203 | 280 | | |
204 | 281 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
323 | 325 | | |
324 | 326 | | |
325 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
326 | 341 | | |
327 | 342 | | |
328 | 343 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
380 | 393 | | |
381 | 394 | | |
382 | 395 | | |
| |||
0 commit comments