Add `with_rank` param to `Dataset.filter`
State: closed

Fix #6564 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/datasets/pr_6608). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

<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.005376 / 0.011353 (-0.005977) | 0.004691 / 0.011008 (-0.006317) | 0.064061 / 0.038508 (0.025553) | 0.030397 / 0.023109 (0.007288) | 0.242656 / 0.275898 (-0.033242) | 0.275586 / 0.323480 (-0.047894) | 0.003460 / 0.007986 (-0.004526) | 0.003125 / 0.004328 (-0.001203) | 0.050496 / 0.004250 (0.046246) | 0.045833 / 0.037052 (0.008781) | 0.255222 / 0.258489 (-0.003267) | 0.287303 / 0.293841 (-0.006538) | 0.027755 / 0.128546 (-0.100791) | 0.011251 / 0.075646 (-0.064396) | 0.208456 / 0.419271 (-0.210816) | 0.037219 / 0.043533 (-0.006314) | 0.249592 / 0.255139 (-0.005547) | 0.261243 / 0.283200 (-0.021957) | 0.020735 / 0.141683 (-0.120948) | 1.130017 / 1.452155 (-0.322137) | 1.208558 / 1.492716 (-0.284158) |

### 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.098891 / 0.018006 (0.080885) | 0.439042 / 0.000490 (0.438552) | 0.000333 / 0.000200 (0.000133) | 0.000045 / 0.000054 (-0.000010) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.018356 / 0.037411 (-0.019055) | 0.062416 / 0.014526 (0.047891) | 0.075613 / 0.176557 (-0.100944) | 0.122009 / 0.737135 (-0.615126) | 0.078195 / 0.296338 (-0.218144) |

### 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.273804 / 0.215209 (0.058595) | 2.706480 / 2.077655 (0.628826) | 1.456196 / 1.504120 (-0.047924) | 1.353301 / 1.541195 (-0.187893) | 1.378913 / 1.468490 (-0.089577) | 0.556885 / 4.584777 (-4.027892) | 2.358961 / 3.745712 (-1.386752) | 2.871830 / 5.269862 (-2.398031) | 1.765212 / 4.565676 (-2.800464) | 0.062172 / 0.424275 (-0.362103) | 0.004974 / 0.007607 (-0.002633) | 0.330375 / 0.226044 (0.104331) | 3.264550 / 2.268929 (0.995621) | 1.824444 / 55.444624 (-53.620181) | 1.561189 / 6.876477 (-5.315287) | 1.671020 / 2.142072 (-0.471052) | 0.633408 / 4.805227 (-4.171819) | 0.116080 / 6.500664 (-6.384584) | 0.044606 / 0.075469 (-0.030863) |

### 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) | 0.980757 / 1.841788 (-0.861031) | 12.553534 / 8.074308 (4.479225) | 10.517668 / 10.191392 (0.326276) | 0.130528 / 0.680424 (-0.549896) | 0.013960 / 0.534201 (-0.520241) | 0.289615 / 0.579283 (-0.289668) | 0.267277 / 0.434364 (-0.167087) | 0.324139 / 0.540337 (-0.216198) | 0.440325 / 1.386936 (-0.946611) |

</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.005388 / 0.011353 (-0.005965) | 0.004043 / 0.011008 (-0.006966) | 0.050514 / 0.038508 (0.012005) | 0.031413 / 0.023109 (0.008303) | 0.275122 / 0.275898 (-0.000776) | 0.307518 / 0.323480 (-0.015962) | 0.004440 / 0.007986 (-0.003546) | 0.003301 / 0.004328 (-0.001027) | 0.049200 / 0.004250 (0.044949) | 0.045704 / 0.037052 (0.008651) | 0.285265 / 0.258489 (0.026776) | 0.318942 / 0.293841 (0.025101) | 0.053893 / 0.128546 (-0.074653) | 0.011855 / 0.075646 (-0.063791) | 0.060951 / 0.419271 (-0.358321) | 0.034397 / 0.043533 (-0.009136) | 0.276108 / 0.255139 (0.020969) | 0.290981 / 0.283200 (0.007781) | 0.019986 / 0.141683 (-0.121697) | 1.205695 / 1.452155 (-0.246460) | 1.255942 / 1.492716 (-0.236774) |

### 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.101910 / 0.018006 (0.083904) | 0.320551 / 0.000490 (0.320061) | 0.000299 / 0.000200 (0.000099) | 0.000058 / 0.000054 (0.000004) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.022387 / 0.037411 (-0.015024) | 0.076380 / 0.014526 (0.061854) | 0.090404 / 0.176557 (-0.086153) | 0.127106 / 0.737135 (-0.610030) | 0.089873 / 0.296338 (-0.206465) |

### 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.288433 / 0.215209 (0.073223) | 2.827005 / 2.077655 (0.749350) | 1.548760 / 1.504120 (0.044640) | 1.419545 / 1.541195 (-0.121650) | 1.456531 / 1.468490 (-0.011959) | 0.570254 / 4.584777 (-4.014523) | 2.441318 / 3.745712 (-1.304394) | 2.778647 / 5.269862 (-2.491215) | 1.755255 / 4.565676 (-2.810422) | 0.062581 / 0.424275 (-0.361694) | 0.005205 / 0.007607 (-0.002402) | 0.342189 / 0.226044 (0.116145) | 3.401208 / 2.268929 (1.132279) | 1.941447 / 55.444624 (-53.503178) | 1.652578 / 6.876477 (-5.223899) | 1.768558 / 2.142072 (-0.373514) | 0.656537 / 4.805227 (-4.148690) | 0.116901 / 6.500664 (-6.383763) | 0.041408 / 0.075469 (-0.034061) |

### 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.001715 / 1.841788 (-0.840073) | 12.533073 / 8.074308 (4.458765) | 11.086084 / 10.191392 (0.894692) | 0.134368 / 0.680424 (-0.546055) | 0.015255 / 0.534201 (-0.518946) | 0.291769 / 0.579283 (-0.287514) | 0.283311 / 0.434364 (-0.151053) | 0.327857 / 0.540337 (-0.212481) | 0.413854 / 1.386936 (-0.973083) |

</details>
</details>

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