Commit 1f758c2
committed
[SPARK-55296][PS] Support CoW mode with pandas 3
### What changes were proposed in this pull request?
Support CoW (Copy-on-Write) mode with pandas 3.
### Why are the changes needed?
Pandas 3 is doing copy-on-write for everything.
For example:
```py
>>> pdf = pd.DataFrame(
... [[1, 2], [4, 5], [7, 8]],
... index=["cobra", "viper", "sidewinder"],
... columns=["max_speed", "shield"],
... )
>>>
>>> pser1 = pdf.max_speed
>>> pser2 = pdf.shield
>>>
>>> pdf.loc[["viper", "sidewinder"], ["max_speed", "shield"]] = 10
```
- pandas 2
```py
>>> pdf
max_speed shield
cobra 1 2
viper 10 10
sidewinder 10 10
>>> pser1
cobra 1
viper 10
sidewinder 10
Name: max_speed, dtype: int64
>>> pser2
cobra 2
viper 10
sidewinder 10
Name: shield, dtype: int64
```
- pandas 3
```py
>>> pdf
max_speed shield
cobra 1 2
viper 10 10
sidewinder 10 10
>>> pser1
cobra 1
viper 4
sidewinder 7
Name: max_speed, dtype: int64
>>> pser2
cobra 2
viper 5
sidewinder 8
Name: shield, dtype: int64
```
Or for `Series`:
```py
>>> pdf = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]}, index=["cobra", "viper", "sidewinder"])
>>>
>>> pser = pdf.x
>>> psery = pdf.y
>>>
>>> pser.loc[pser % 2 == 1] = -pser
```
- pandas 2
```py
>>> pdf
x y
cobra -1 4
viper 2 5
sidewinder -3 6
>>> pser
cobra -1
viper 2
sidewinder -3
Name: x, dtype: int64
>>> psery
cobra 4
viper 5
sidewinder 6
Name: y, dtype: int64
```
- pandas 3
```py
>>> pdf
x y
cobra 1 4
viper 2 5
sidewinder 3 6
>>> pser
cobra -1
viper 2
sidewinder -3
Name: x, dtype: int64
>>> psery
cobra 4
viper 5
sidewinder 6
Name: y, dtype: int64
```
### Does this PR introduce _any_ user-facing change?
Yes, it will behave more like pandas 3.
### How was this patch tested?
Updated the related tests to make it clear, but basically the existing tests should pass.
### Was this patch authored or co-authored using generative AI tooling?
Codex (GPT-5.3-Codex)
Closes #54375 from ueshin/issues/SPARK-55296/cow.
Authored-by: Takuya Ueshin <ueshin@databricks.com>
Signed-off-by: Takuya Ueshin <ueshin@databricks.com>1 parent 6806c8b commit 1f758c2
File tree
4 files changed
+140
-65
lines changed- python/pyspark/pandas
- tests/indexes
4 files changed
+140
-65
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
720 | 721 | | |
721 | 722 | | |
722 | 723 | | |
723 | | - | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
724 | 731 | | |
725 | 732 | | |
726 | 733 | | |
| |||
737 | 744 | | |
738 | 745 | | |
739 | 746 | | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
740 | 771 | | |
741 | 772 | | |
742 | 773 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
434 | 437 | | |
435 | 438 | | |
436 | 439 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
183 | | - | |
184 | | - | |
185 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
186 | 188 | | |
187 | 189 | | |
188 | 190 | | |
| |||
Lines changed: 99 additions & 60 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
240 | 241 | | |
241 | 242 | | |
242 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
243 | 296 | | |
244 | 297 | | |
245 | 298 | | |
246 | 299 | | |
247 | 300 | | |
248 | 301 | | |
249 | 302 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | 303 | | |
292 | 304 | | |
293 | 305 | | |
| |||
296 | 308 | | |
297 | 309 | | |
298 | 310 | | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
304 | 345 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
316 | 354 | | |
317 | 355 | | |
318 | 356 | | |
| |||
322 | 360 | | |
323 | 361 | | |
324 | 362 | | |
325 | | - | |
326 | | - | |
327 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
328 | 367 | | |
329 | 368 | | |
330 | 369 | | |
| |||
0 commit comments