Make IterableDataset.from_spark more efficient
CONTRIBUTOR
@lhoestq would you be able to review this please and also approve the workflow?
2023-07-05T17:21:03Z
https://github.com/huggingface/datasets/pull/5986#issuecomment-1622177194
https://api.github.com/repos/huggingface/datasets/issues/5986
IC_kwDODunzps5gsHWq
https://api.github.com/repos/huggingface/datasets/issues/comments/1622177194/reactions
2023-07-05T17:21:03Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1622177194
https://avatars.githubusercontent.com/u/106995444?v=4
https://api.github.com/users/maddiedawson/events{/privacy}
https://api.github.com/users/maddiedawson/followers
https://api.github.com/users/maddiedawson/following{/other_user}
https://api.github.com/users/maddiedawson/gists{/gist_id}
https://github.com/maddiedawson
maddiedawson
U_kgDOBmCe9A
https://api.github.com/users/maddiedawson/orgs
https://api.github.com/users/maddiedawson/received_events
https://api.github.com/users/maddiedawson/repos
https://api.github.com/users/maddiedawson/starred{/owner}{/repo}
https://api.github.com/users/maddiedawson/subscriptions
User
https://api.github.com/users/maddiedawson
public
MEMBER
Sounds good to me :) feel free to run `make style` to apply code formatting
2023-07-06T09:40:43Z
https://github.com/huggingface/datasets/pull/5986#issuecomment-1623359134
https://api.github.com/repos/huggingface/datasets/issues/5986
IC_kwDODunzps5gwn6e
https://api.github.com/repos/huggingface/datasets/issues/comments/1623359134/reactions
2023-07-06T09:40:43Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1623359134
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
NONE
_The documentation is not available anymore as the PR was closed or merged._
2023-07-06T09:44:55Z
https://github.com/huggingface/datasets/pull/5986#issuecomment-1623366517
https://api.github.com/repos/huggingface/datasets/issues/5986
IC_kwDODunzps5gwpt1
https://api.github.com/repos/huggingface/datasets/issues/comments/1623366517/reactions
2023-07-07T09:56:36Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1623366517
https://avatars.githubusercontent.com/u/99929124?v=4
https://api.github.com/users/HuggingFaceDocBuilderDev/events{/privacy}
https://api.github.com/users/HuggingFaceDocBuilderDev/followers
https://api.github.com/users/HuggingFaceDocBuilderDev/following{/other_user}
https://api.github.com/users/HuggingFaceDocBuilderDev/gists{/gist_id}
https://github.com/HuggingFaceDocBuilderDev
HuggingFaceDocBuilderDev
U_kgDOBfTMJA
https://api.github.com/users/HuggingFaceDocBuilderDev/orgs
https://api.github.com/users/HuggingFaceDocBuilderDev/received_events
https://api.github.com/users/HuggingFaceDocBuilderDev/repos
https://api.github.com/users/HuggingFaceDocBuilderDev/starred{/owner}{/repo}
https://api.github.com/users/HuggingFaceDocBuilderDev/subscriptions
User
https://api.github.com/users/HuggingFaceDocBuilderDev
public
MEMBER
cool ! I think we can merge once all comments have been addressed
2023-07-06T16:32:53Z
https://github.com/huggingface/datasets/pull/5986#issuecomment-1623976935
https://api.github.com/repos/huggingface/datasets/issues/5986
IC_kwDODunzps5gy-vn
https://api.github.com/repos/huggingface/datasets/issues/comments/1623976935/reactions
2023-07-06T16:32:53Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1623976935
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
@lhoestq I just addressed the comments and I think we can move ahead with this! 

2023-07-06T17:41:13Z
https://github.com/huggingface/datasets/pull/5986#issuecomment-1624079323
https://api.github.com/repos/huggingface/datasets/issues/5986
IC_kwDODunzps5gzXvb
https://api.github.com/repos/huggingface/datasets/issues/comments/1624079323/reactions
2023-07-06T17:41:13Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1624079323
https://avatars.githubusercontent.com/u/134338709?v=4
https://api.github.com/users/mathewjacob1002/events{/privacy}
https://api.github.com/users/mathewjacob1002/followers
https://api.github.com/users/mathewjacob1002/following{/other_user}
https://api.github.com/users/mathewjacob1002/gists{/gist_id}
https://github.com/mathewjacob1002
mathewjacob1002
U_kgDOCAHYlQ
https://api.github.com/users/mathewjacob1002/orgs
https://api.github.com/users/mathewjacob1002/received_events
https://api.github.com/users/mathewjacob1002/repos
https://api.github.com/users/mathewjacob1002/starred{/owner}{/repo}
https://api.github.com/users/mathewjacob1002/subscriptions
User
https://api.github.com/users/mathewjacob1002
public
NONE
<details>
<summary>Show benchmarks</summary>

PyArrow==8.0.0

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.007734 / 0.011353 (-0.003619) | 0.004608 / 0.011008 (-0.006400) | 0.094466 / 0.038508 (0.055958) | 0.086477 / 0.023109 (0.063368) | 0.410311 / 0.275898 (0.134413) | 0.455560 / 0.323480 (0.132080) | 0.006112 / 0.007986 (-0.001874) | 0.003845 / 0.004328 (-0.000483) | 0.072506 / 0.004250 (0.068256) | 0.066721 / 0.037052 (0.029669) | 0.409967 / 0.258489 (0.151478) | 0.460480 / 0.293841 (0.166639) | 0.036700 / 0.128546 (-0.091847) | 0.009854 / 0.075646 (-0.065792) | 0.320936 / 0.419271 (-0.098335) | 0.061002 / 0.043533 (0.017469) | 0.413963 / 0.255139 (0.158824) | 0.426787 / 0.283200 (0.143588) | 0.029182 / 0.141683 (-0.112501) | 1.685136 / 1.452155 (0.232981) | 1.754590 / 1.492716 (0.261873) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.222698 / 0.018006 (0.204692) | 0.505929 / 0.000490 (0.505440) | 0.005291 / 0.000200 (0.005091) | 0.000097 / 0.000054 (0.000042) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.032527 / 0.037411 (-0.004884) | 0.094842 / 0.014526 (0.080317) | 0.110138 / 0.176557 (-0.066418) | 0.193786 / 0.737135 (-0.543349) | 0.112593 / 0.296338 (-0.183745) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.441671 / 0.215209 (0.226461) | 4.392961 / 2.077655 (2.315306) | 2.161111 / 1.504120 (0.656991) | 1.967080 / 1.541195 (0.425885) | 2.065411 / 1.468490 (0.596920) | 0.561080 / 4.584777 (-4.023697) | 4.159612 / 3.745712 (0.413900) | 6.435248 / 5.269862 (1.165386) | 3.732338 / 4.565676 (-0.833339) | 0.066156 / 0.424275 (-0.358119) | 0.008030 / 0.007607 (0.000423) | 0.532182 / 0.226044 (0.306137) | 5.315142 / 2.268929 (3.046213) | 2.680157 / 55.444624 (-52.764467) | 2.303799 / 6.876477 (-4.572677) | 2.530911 / 2.142072 (0.388838) | 0.669504 / 4.805227 (-4.135723) | 0.151940 / 6.500664 (-6.348724) | 0.066999 / 0.075469 (-0.008470) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.424275 / 1.841788 (-0.417513) | 21.550742 / 8.074308 (13.476434) | 16.031414 / 10.191392 (5.840022) | 0.194681 / 0.680424 (-0.485743) | 0.020389 / 0.534201 (-0.513812) | 0.429808 / 0.579283 (-0.149475) | 0.457503 / 0.434364 (0.023139) | 0.511522 / 0.540337 (-0.028816) | 0.682621 / 1.386936 (-0.704315) |

</details>
PyArrow==latest

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.007519 / 0.011353 (-0.003834) | 0.004445 / 0.011008 (-0.006563) | 0.071946 / 0.038508 (0.033438) | 0.082982 / 0.023109 (0.059873) | 0.459938 / 0.275898 (0.184040) | 0.504875 / 0.323480 (0.181395) | 0.005805 / 0.007986 (-0.002181) | 0.003740 / 0.004328 (-0.000589) | 0.071998 / 0.004250 (0.067747) | 0.062580 / 0.037052 (0.025527) | 0.462263 / 0.258489 (0.203774) | 0.506355 / 0.293841 (0.212514) | 0.036321 / 0.128546 (-0.092225) | 0.009830 / 0.075646 (-0.065816) | 0.079810 / 0.419271 (-0.339461) | 0.055291 / 0.043533 (0.011758) | 0.464093 / 0.255139 (0.208954) | 0.481109 / 0.283200 (0.197910) | 0.026909 / 0.141683 (-0.114774) | 1.652538 / 1.452155 (0.200383) | 1.750713 / 1.492716 (0.257997) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.267552 / 0.018006 (0.249546) | 0.502021 / 0.000490 (0.501531) | 0.001635 / 0.000200 (0.001435) | 0.000099 / 0.000054 (0.000044) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.033747 / 0.037411 (-0.003665) | 0.104242 / 0.014526 (0.089716) | 0.113829 / 0.176557 (-0.062728) | 0.176242 / 0.737135 (-0.560893) | 0.117002 / 0.296338 (-0.179336) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.476731 / 0.215209 (0.261522) | 4.727054 / 2.077655 (2.649399) | 2.589396 / 1.504120 (1.085276) | 2.511180 / 1.541195 (0.969985) | 2.634122 / 1.468490 (1.165632) | 0.563840 / 4.584777 (-4.020937) | 4.140212 / 3.745712 (0.394500) | 6.188789 / 5.269862 (0.918928) | 3.716897 / 4.565676 (-0.848780) | 0.065823 / 0.424275 (-0.358452) | 0.007705 / 0.007607 (0.000098) | 0.566580 / 0.226044 (0.340535) | 5.653306 / 2.268929 (3.384377) | 3.028756 / 55.444624 (-52.415868) | 2.592319 / 6.876477 (-4.284158) | 2.614250 / 2.142072 (0.472178) | 0.667135 / 4.805227 (-4.138093) | 0.153455 / 6.500664 (-6.347209) | 0.069321 / 0.075469 (-0.006148) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.541978 / 1.841788 (-0.299810) | 21.747360 / 8.074308 (13.673052) | 15.963657 / 10.191392 (5.772265) | 0.192843 / 0.680424 (-0.487581) | 0.020702 / 0.534201 (-0.513499) | 0.433620 / 0.579283 (-0.145663) | 0.467327 / 0.434364 (0.032963) | 0.507398 / 0.540337 (-0.032940) | 0.692797 / 1.386936 (-0.694140) |

</details>
</details>

![](https://cml.dev/watermark.png#396cf9419d12e3150e2051793b10f2c813780a90 "CML watermark")

2023-07-07T10:05:58Z
https://github.com/huggingface/datasets/pull/5986#issuecomment-1625176426
https://api.github.com/repos/huggingface/datasets/issues/5986
IC_kwDODunzps5g3jlq
https://api.github.com/repos/huggingface/datasets/issues/comments/1625176426/reactions
2023-07-07T10:05:58Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1625176426
https://avatars.githubusercontent.com/in/15368?v=4
https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}
https://api.github.com/users/github-actions%5Bbot%5D/followers
https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}
https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}
https://github.com/apps/github-actions
github-actions[bot]
MDM6Qm90NDE4OTgyODI=
https://api.github.com/users/github-actions%5Bbot%5D/orgs
https://api.github.com/users/github-actions%5Bbot%5D/received_events
https://api.github.com/users/github-actions%5Bbot%5D/repos
https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}
https://api.github.com/users/github-actions%5Bbot%5D/subscriptions
Bot
https://api.github.com/users/github-actions%5Bbot%5D
public
Moved the code from using collect() to using toLocalIterator, which allows for prefetching partitions that will be selected next, thus allowing for better performance when iterating. 